Can anyone advise, how to verify specific color using css?
I can do it with xpath locator. But I cannot with css.
This is xpath locator which is working:
//div[10][@style="b开发者_JAVA百科ackground-color: rgb(255, 76, 219);"]
You need to use getCssValue
WebElement element = driver.findElement(By.id("foo"));
String backgroundColor = element.getCssValue("background-color");
Just starting with Selenium myself. Awesome testing tool!
Did some searching and found: //tr[@bgcolor/text()="tan"]
Perhaps you can do: //div[10][@bgcolor/text()="#814c1b"]
src: http://old.nabble.com/Using-Selenium-to-find-a-row-based-on-it's-background-color-td24859281.html
This is not possible with CSS locators, AFAIK.
Your best best to avoid XPath is a gnarly DOM locator like:
dom=(var divs = document.getElementsByTagName('div'); var targets = []; for (div in divs) { if (divs.hasOwnProperty(div) && div.style.backgroundColor == 'rgb(255, 76, 219)') targets.push(div); })
You might consider testing for a given selector instead, like:
css=div.red
Once look at this,It may solve your problem
Get color attribute
精彩评论