Selenium Webdriver:鼠标光标悬停不起作用

时间:2017-02-26 08:18:17

标签: selenium selenium-webdriver

Selenium Webdriver:鼠标光标悬停不适用于firefox版本50

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
public class Ajax_Mouse_Interactions {
public static void main(String[] args) throws InterruptedException {

firefox驱动程序的路径

System.setProperty("webdriver.gecko.driver",
"C://Users//user2//Downloads//geckodriver-v0.11.1-win64//geckodriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("http://www.amazon.in/");        

Thread.sleep(20000);                        

鼠标处理的动作类

Actions action = new Actions(driver);

WebElement element=driver.findElement(By.linkText("nav-link-yourAccount"));

action.moveToElement(element).build().perform();
} 
}

获得以下异常

Upsupported Command Exception

3 个答案:

答案 0 :(得分:0)

我现在正在尝试这个。 这段代码适合我。

import java.awt.Robot;
...
Point point = webDriver.findElement(By.xpath("//a[@title='Emitir Guias']")).getLocation();
System.out.println(point.toString());
Robot robot = new Robot();
robot.mouseMove(point.x+10,point.y+110); //This 10 and 110 just to adjust coordenate in my case

Thread.sleep(3000); //Pause for you see the mouse move

来源https://stackoverflow.com/posts/12978079/revisions

答案 1 :(得分:0)

Gecodriver + Selenium 3.0.1与Actions类有问题。

有关详细信息,请参阅以下链接。

https://github.com/mozilla/geckodriver/issues/233

https://github.com/mozilla/geckodriver/issues/322

https://github.com/SeleniumHQ/selenium/issues/2581

所以dvice是回退到selenium v​​2.53.1和firefox浏览器47.0

谢谢!

答案 2 :(得分:0)

       For selenium webdriverjs 3.6 javascript mouseMove can be used for mouse hover
        const actions = driver.actions({ bridge: true });
        driver.findElement(By.css('#mousehover'))
            .then(function (elem) {
                actions.mouseMove(elem).perform();
                driver.sleep(1000)
                // other actions..
            });`