开发者

How to handle popovers using Selenium Webdriver + Python

Here is the situation - On the website that I am testing, the page source changes dynamically i.e. when I move my mouse over an element I see a popover and it has DOM structure and all. I want to capture the DOM elements in the popover.

I am using webdriver with python. It works well when I use IDLE because the popover stays on the webpage awhile and I can capture the DOM structure. However, when I try to execute that in 开发者_StackOverflow中文版a script, the popover merely flashes on the screen and I cannot capture the DOM structure.

I have tried using WebDriverWait, Actions API etc. But nothing is working. Any pointers will be appreciated. Thanks.


Use Actions to hover the mouse over the element. The straight-forward approach is something like this (sorry the code is in C#):

IWebElement element = driver.FindElement(By.Id("something")); 
Actions action = new Actions(driver); 
actions.MoveToElement(element);
actions.Perform();

//get the DOM structure

Important is to not forget the Perform() call. If this doesn't work (which sometimes it just doesn't), replace MoveToElement with ClickAndHold. Usually this keeps things like mouseover pop ups open indefinitely.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜