2

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!!!!");
3
  • 1
    Please show the html code snippet for more clarity? Commented Nov 22, 2012 at 10:03
  • 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. Commented Nov 22, 2012 at 10:48
  • It shows the popup window as in the window we need to enter the values. It waits there and gives the error. Commented Nov 23, 2012 at 8:32

2 Answers 2

1

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")));
Sign up to request clarification or add additional context in comments.

Comments

0

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

1 Comment

Hi Anurag, thanks for the reply, i have already tried this. but unfortunately it doesn't worked as it is not taking that frame. it gives the title of main window only and not the child windows :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.