如何确定按钮的颜色?在我的情况下,标准按钮是白色的,但在我点击它之后,它变成了蓝色。我该怎么检查它真的变蓝了?
我希望颜色的变化是由一些css属性,如background-color,所以只需检查它。
String color = driver.findElements(By.cssSelector("#dummy")).getCssValue("background-color");
如果仅在单击按钮时更改颜色并在发布时恢复颜色,则必须使用操作单击并按住按钮,然后检查CSS值。否则,您只需检查background-color属性的CSS值即可。
new Actions(driver).clickAndHold(btnCreateVRIPack).perform();
element.getCssValue("background-color")
WebElement newBtn = driver.findElement(By.xpath("");
Actions action = new Actions(driver);
action.moveToElement(newBtn).perform();
System.out.println("Color of a button : " + newBtn.getCssValue("bg-color"));