【问题标题】:Selenium testing of Hover propertyHover 属性的硒测试
【发布时间】:2014-08-13 04:37:00
【问题描述】:

我需要在悬停时测试 #F67621 的背景颜色变化。 背景颜色代码将与预定义的预期值进行比较。我使用 XPath 作为选择器。

String xPathStr="//input[@id='add']";
String str = driver.findElement(By.xpath(xPathStr)).getCssValue("background-color");

对于上面的代码,有人可以建议我如何检查按钮的悬停
上述代码的CSS如下:

# add:hover , #clear:hover{
    background-color:#F67621;
}

【问题讨论】:

    标签: java selenium xpath selenium-webdriver


    【解决方案1】:

    我不确定,但我发现了这个:

    How to perform mouseover function in Selenium WebDriver using Java?

    Actions action = new Actions(driver);
    WebElement we = driver.findElement(By.id("Add"));
    action.moveToElement(we).perform();
    assertEquals("#F67621", we.getCssValue("background-color"));
    

    其他链接:

    http://www.learnseleniumtesting.com/mouse-hover-and-other-mouse-events-in-webdriver/

    【讨论】:

      【解决方案2】:
      WebElement mousehover=org.findElement(By.xpath("html/body/div[1]/div/div[1]/div/div/div[2]/div[1]/ul/li[3]/a"));
      Actions action = new Actions(org);
      action.moveToElement(mousehover).build().perform();
      

      【讨论】:

      • 单独的代码块并不能提供好的答案。请添加解释(为什么它解决了问题,错误在哪里等等......)
      猜你喜欢
      • 2019-02-06
      • 2011-02-15
      • 1970-01-01
      • 2015-07-06
      • 2012-10-15
      • 1970-01-01
      • 2011-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多