- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to verify the color and background color of a web element in Selenium?
We can verify the color and background color of a web element in Selenium with the help of getCSSValue() method.
Example
import org.openqa.selenium.By; import org.openqa.selenium.Keys; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; public class CssColorValue { public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = "https://www.tutorialspoint.com/index.htm"; driver.get(url); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); //getting color attribute with getCssValue() String colr = driver.findElement(By.xpath("//*[text()=’GATE Exams’]")) .getCssValue("color"); //getting background color attribute with getCssValue() String bckgclr = driver.findElement(By.xpath("//*[text()=’ ’GATE Exams’]")) .getCssValue("background-color"); System.out.println(colr); System.out.println(bckgclr); driver.close(); } }
- Related Articles
- How to verify color of a web element in Selenium Webdriver?
- How to display the background color of an element in HTML?
- Change Background color of a web page using onmouseover property
- How to choose a background color through a color picker in JavaScript?
- How to return the background color of an element with JavaScript DOM?
- Set the background color of an element with CSS
- Add hover color to background color of the table row in Bootstrap
- Customize the tooltip font, color , background and foreground color in Java
- How to set the background color of a ttk.Combobox in tkinter?
- How to change the background color of a Treeview in Tkinter?
- How to set background color in jQuery?
- How to set background color in HTML?
- How to change the background color using jQuery?
- How to reset the background color of a Python Tkinter button?
- How to change the background color of a tkinter Canvas dynamically?

Advertisements