user1844541
user1844541

Reputation: 21

Sharepoint modal window handling through Selenium webdriver

I am automating the sharepoint application using Selenium webdriver.

On clicking one link to add the new item to the list, it opens the window/frame (not sure of), sort of modal pop up window. while executing the script, it is giving error of unable to locate element. In the below image, when i used to find all the window handles using driver.getwindowhandles(), it just gives 1 window as the parent window. and not the child window. The same code is able to run through selenium IDE but not thru JUnit. please help how can i handle this thing.

driver.findElement(By.xpath("//div[@id='zz9_V4QuickLaunchMenu']/div/ul/li[4]/a/span/span")).click();
driver.findElement(By.id("idHomePageNewLink")).click();
Thread.sleep(5000);

//gives error at this point which is the id of the text field on child popup window.

driver.findElement(By.id("ctl00_m_g_99918f84_a256_44b4_819e_982688a9f15c_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_UrlFieldUrl")).clear();        
driver.findElement(By.id("ctl00_m_g_99918f84_a256_44b4_819e_982688a9f15c_ctl00_ctl05_ctl00_ctl00_ctl00_ctl04_ctl00_ctl00_UrlFieldUrl")).sendKeys("http://efgh");
System.out.println("Done!!!!");

Upvotes: 2

Views: 2408

Answers (2)

Amol Dakhane
Amol Dakhane

Reputation: 11

I have had a similar problem, which I have solved using the SwitchTo().Frame method provided by the Selenium webdriver. Use the following code to set focus to the SharePoint modal file upload dialog:

driver.SwitchTo().Frame(driver.FindElement(By.ClassName("ms-dlgFrame")));

Upvotes: 1

Anuragh27crony
Anuragh27crony

Reputation: 2957

in SharePoint for New item form you don't need to switch the windows. Since Selenium considers everything as one page and the code is auto detected.

Coming to main point, New Item form window contains IFrames internally which contains the textboxes/other data consuming objects.

Do try via switching frames.Generally there will be 2 IFrame windows in New item window ...do check the HTML code of New Item form window.

Driver.SwitchTo().Frame(1);
Console.WriteLine(Driver.Title);

All the best...Hope this helps :-)

Upvotes: 0

Related Questions