简体   繁体   中英

How to determine the color of an element using Java using Selenium WebDriver?

How to determine the color of the button? In my case, the standard button is white , but after I clicked on it, it turned blue . How can I check that it really turned blue?

我希望颜色更改是由一些 css 属性(如 background-color)进行的,所以只需检查它。

String color = driver.findElements(By.cssSelector("#dummy")).getCssValue("background-color");

If the color change is only when the button is clicked and reverts the color on release then you have to use actions to click and hold on the button and then check the CSS value. Otherwise, you can just check the CSS value of the background-color attribute.

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"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM