【问题标题】:Selenium 2 + phantom js: unable to perform actions on a mouseoverSelenium 2 + phantom js:无法在鼠标悬停时执行操作
【发布时间】:2014-04-14 16:15:45
【问题描述】:

我正在尝试对从未完成的按钮执行操作。

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 上无法运行

我在这里How to handle Mouseover in Selenium 2 APIHow to perform mouseover function in Selenium WebDriver using Java? 发现了一些问题,但对幻像没有任何作用。

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

谢谢!

【问题讨论】:

    标签: java selenium phantomjs mouseover


    【解决方案1】:

    大约一年前,我在使用 GhostDriver 和 PhantomJS 时遇到了类似的问题 (FYI article)。实际上我也遇到了 IE_Driver 和 Chrome_Driver 的问题,主要与 screen_frame 之外的元素的可见性有关(页面必须向下滚动)。

    最严重的问题之一是upload_window 并通过已经提到的处理它。我无法实现它。但我的解决方法是在这些有问题的地方切换/投射驱动程序,并在它们完成/处理操作后 - 将其切换回 GhostDriver。即使这样做,执行速度也令人印象深刻。

    希望这会有所帮助——即使是迟到的。

    更新:

    find IWebElement to process
    set WebDriver from GhostDriver to FirefoxDriver
    process the IWebElement item with current WebDriver as FirefoxDriver
    verify expected result from processing the IWebElement item
    set back WebDriver from FirefoxDriver to GhostDriver 
    continue workflow
    

    据我记得我的测试框架实现 - 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();
    

    【讨论】:

    • 您能否详细说明切换/强制转换驱动程序 的含义?也许提供代码示例。
    • 遗憾的是,我将此代码实现留给了我以前的项目。但是,如果您的测试框架是使用适当的类层次结构和抽象级别构建的,那么我更新的答案中的伪代码将不得不做得很好。
    猜你喜欢
    • 2023-03-07
    • 2017-08-18
    • 1970-01-01
    • 2017-01-21
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多