Mouse the focus to an object using selenium python

半世苍凉 提交于 2021-02-08 07:30:31

问题


I am automating a website using selenium RC and python 2.7 on Ubuntu Linux. Here is what I need to do:

Go to the site http://borro.com.
Scroll down to the bottom of the page using key down native command I need to hover the mouse on g +1 read the tool tip
click on the name that appears in the tool tip.

The problem I am having is -- I need the mouse to physically move there, wait for say 2 secs and then read the tool tip and click on the name

The mouse is not physically moving there and I think the focus is lost and it says element xpath not found. enter image description here


回答1:


We've solved a lot of our focus issues by sending a blank key to the element so it gets focused. In this case, you'd probably want to send blank key to the tooltip as soon as it appears. I'm familiar with webdriver but not RC, but RC should have something like send_key(element_xpath, " ") as well.

To get the tooltip's xpath, you can use firebug, and in the console, use something like

$x("//*[contains(text(), 'Publicly recommend this as')]") 

to make sure this element is found and xpath is correct. I also recommend not using wildcard characters, so once you find the tooltip's xpath, try to replace the * by the actual element type.




回答2:


Button Xpath and on hover on button xpath are given below

   Actions builder = new Actions(driver);
   WebElement tagElement = driver.findElement(By.id("button"));
   builder.moveToElement(tagElement).build().perform();

         /html/body/div/div/table/tbody/tr/td/div

Try:

          selenium.mouseOver("mylocator");


来源:https://stackoverflow.com/questions/13250908/mouse-the-focus-to-an-object-using-selenium-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!