硒等待弹出 [英] Selenium waitforpopup
问题描述
如何在弹出窗口打开之前停止硒服务器?
How to stop the selenium server until a popup opens?
我们有selenium.waitForPageToLoad
可以停止服务器,直到页面加载为止.但是有什么方法可以阻止Popup吗?
We have selenium.waitForPageToLoad
to stop the server until the Page Loads. But is there any way to stop it for Popup?
我用selenium.WaitForPopup
尝试过,但是找不到弹出窗口ID.因为我创建了一个带有div元素(其ID为popup_container)的弹出框.
I tried it with selenium.WaitForPopup
, but I can't find popup id. Because I created a popup box with div element(whose id is popup_container).
我尝试了以下代码:
selenium.WaitForPopUp("id=popup_container", "30000");
但这不起作用.有帮助吗?
But that doesn't work. Any help?
推荐答案
您的弹出窗口"实际上不是弹出窗口,它只是一个div标签.因此,您要等到该元素(div标签)出现.有一种方法可以检查元素是否存在:
Your 'popup' is not actually a popup, it's just a div tag. So you want to wait until that element (div tag) is present. There is a method to check if the element is present:
selenium.IsElementPresent(div_of_the_popup)
您可以循环检查,直到元素存在或特定时间到期为止.您可以在其他问题/答案中查看示例循环.
You can loop checking until the element is present or a certain time expires. You can see sample loops at this other question/answer.
Selenium的更高版本确实包含用于执行wait元素的方法.最终,解决问题的关键是等待DIV而不是弹出窗口.
The later versions of Selenium, do include methods for doing the wait for element. Ultimately, the key to your problem is waiting for the DIV not a popup.
更新:根据您的其他帖子,您似乎正在使用Selenium-Webdriver.如果是这样,则可以将硒网页中的示例用于显式等待
UPDATE: Based on your other posts, it looks like you are using Selenium-Webdriver. If so, then you can use the example from the selenium web page for explicit waits
这篇关于硒等待弹出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!