我需要测试悬停时背景颜色更改为#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;
}
最佳答案
我不确定,但我发现了这个:
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/
关于java - 悬停属性的 Selen 测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24360826/