简体   繁体   English

无法在Selenium Webdriver中处理Sharepoint弹出页面

[英]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. 我正在尝试使用Selenium Webdriver自动化Sharepoint站点,但无法让我的代码识别新弹出窗口中的元素。

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') . 将鼠标悬停在此给我指针, 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. 我已经使用Firebug检查了xpath,这对于弹出窗口中的第一个对象是正确的。 Looking through the xpath I can see that there is no iFrame specified and so trying driver.switchTo().frame(1) did not work. 通过xpath我可以看到没有指定iFrame,因此尝试driver.switchTo().frame(1)不起作用。

I have also tried using driver.getwindowhandles() , but this only returns a single window so there is nothing to switch to. 我也尝试过使用driver.getwindowhandles() ,但这只返回一个窗口,因此无需切换。

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. 最后,我看到其他人建议它可能只是一个计时问题,因为当脚本检查它们时,弹出窗体上的元素尚未创建,所以我尝试使用Thread.sleep(15000)为弹出窗口提供时间生成,但没有成功。

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. 弹出窗口正在更改DOM,但您在更改产生影响之前进行查询。

You need to use Selenium's implicit wait mechanism for this: 您需要使用Selenium的隐式等待机制:

http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp 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. 我尝试访问弹出窗口之前尝试了driver.switchTo().frame(0) ,这样driver.switchTo().frame(0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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