2
votes

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!!!!");
2
Please show the html code snippet for more clarity? - Abhishek_Mishra
sleep is not a correct way to ensure that the pop up has appeared. Do you see the modal popup when u see the execution? It may be that that the popup has not appeared in the 5 seconds and hence the error. - niharika_neo
It shows the popup window as in the window we need to enter the values. It waits there and gives the error. - user1844541

2 Answers

1
votes

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")));
0
votes

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 :-)