Java 硒2&x2B;phantom js:无法在鼠标悬停上执行操作

Java 硒2&x2B;phantom js:无法在鼠标悬停上执行操作,java,selenium,phantomjs,mouseover,Java,Selenium,Phantomjs,Mouseover,我试图在一个按钮上执行一个从未执行过的操作 final Actions action = new Actions(mDriver); final WebElement myCart = mDriver.findElement(By.cssSelector("path to my span"]")); final WebElement myButton = mDriver.findElement(By.cssSelector("path to my button")); a

我试图在一个按钮上执行一个从未执行过的操作

final Actions action = new Actions(mDriver);
    final WebElement myCart = mDriver.findElement(By.cssSelector("path to my span"]"));
    final WebElement myButton = mDriver.findElement(By.cssSelector("path to my button"));
    action.moveToElement(myCart).build().perform();
    action.moveToElement(myButton).click().build().perform();
此代码与firefox完美配合,但与phantom JS不配合

我在这里发现了一些问题,但与幻影无关

是否有任何已知的解决方法


谢谢

大约一年前,当我使用GhostDriver和PhantomJS()时,我遇到了类似的问题。事实上,我在IE_驱动程序和Chrome_驱动程序方面也遇到了问题,主要与屏幕框架外元素的可见性有关(页面必须向下滚动)

其中一个最严重的问题是upload_窗口,并通过前面提到的方式进行处理。我没能做到。但我的解决方法是在这些有问题的地方切换/转换驱动程序,在他们完成/处理操作后,将其切换回GhostDriver。即使这样做,执行速度也令人印象深刻

希望这能有所帮助——即使是迟交的

更新:

就我记忆中的测试框架实现而言,BaseTest类负责初始化使用过的WebDriver和ISelenium对象。因此,对于更具体的案例,您可以尝试以下方法:

// Create a new instance of the Ghost driver
// Notice that the remainder of the code relies on the interface, 
// not the implementation.
WebDriver driver = new GhostDriver();
//do stuff until new driver is needed
driver = new FirefoxDriver();
//do stuff with new driver
//'cast' back after required operations have been completed and verified
driver = new GhostDriver();

你能详细解释一下你所说的“切换/转换驱动程序”是什么意思吗?也许可以提供代码示例。遗憾的是,我把这个代码实现留给了我以前的项目。但是,如果您的测试框架是使用适当的类层次结构和抽象级别构建的,那么我更新的答案中的伪代码就必须很好地完成这项工作。
// Create a new instance of the Ghost driver
// Notice that the remainder of the code relies on the interface, 
// not the implementation.
WebDriver driver = new GhostDriver();
//do stuff until new driver is needed
driver = new FirefoxDriver();
//do stuff with new driver
//'cast' back after required operations have been completed and verified
driver = new GhostDriver();