简体   繁体   中英

Cannot handle Sharepoint pop-up page in Selenium Webdriver

I'm trying to automate a Sharepoint site using Selenium Webdriver, but cannot get my code to recognise the elements on the new popup.

The scenario is as follows; at one point in the script, we click on a link to a new noticeboard item. Hovering over this gives me the pointer, Javascript:OpenPopUpPage('/Lists/Noticeboard/NoticeboardNewFormMain.aspx') . When the link is clicked the popup appears and the parent screen is disabled as expected.

At this point the script tries to identify the first element on the popup:

    try{
        element = driver.findElement(By.xpath("/html/body/form/div[4]/div[1]/div/div[1]/div[2]/div[2]/div[2]/table/tbody/tr/td/div/div/div/div/div[1]/span[1]/table/tbody/tr[2]/td/div[1]/div[3]/span[1]/input"));
    }catch(Exception e){
        Log.error(sRepositoryName + " | txt_Title not found | Exception desc : "+e.getMessage());       
    } 
    return element;

I have checked the xpath using Firebug and this is correct for the first object on the popup. Looking through the xpath I can see that there is no iFrame specified and so trying driver.switchTo().frame(1) did not work.

I have also tried using driver.getwindowhandles() , but this only returns a single window so there is nothing to switch to.

Finally, i had seen others suggest that it may simply be a timing issue as the elements on the popup form have not been created when the script is checking for them, so I tried using Thread.sleep(15000) to give time for the popup to generate, but with no success.

No matter what I try, I still end up with an "Unable to locate element" exception for all elements on the popup. Does anyone have any ideas how to handle these popups?

The popup is changing the DOM but you are querying before the change has had affect.

You need to use Selenium's implicit wait mechanism for this:

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp

It appears that I have found a resolution.

When the popup opens it does not open a new frame, but seems to lose focus on the existing frame. I tried driver.switchTo().frame(0) before attempting to access the popup and this works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM