Is it possible to check if a text is highlighted on the page using Selenium

0 votes
Is it possible to check if a text is highlighted on the page using Selenium?
May 30, 2019 in Selenium by Karan
14,547 views

1 answer to this question.

0 votes

Hey Karan, you can use following code snippet to check whether a text is highlighted on a page using Selenium:

String color = driver.findElement(By.xpath("//a[text()='Shop']")).getCssValue("color");

String backcolor = driver.findElement(By.xpath("//a[text()='Shop']")).getCssValue("background-color");

System.out.println(color);

System.out.println(backcolor);

if(!color.equals(backcolor)){

System.out.println("Text is highlighted!")

}

else{

System.out.println("Text is not highlighted!")
}

Here if both color and back color different then that means that element is in different color.

answered May 30, 2019 by Avni

Related Questions In Selenium

0 votes
1 answer
+1 vote
2 answers

Is it possible to manually set the attribute value of a Web Element using Selenium?

WebDriver driver; JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("document.getElementById('id123').setAttribute('attr', ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
26,738 views
+1 vote
2 answers

Is it possible to scroll down in a webpage using selenium webdriver programmed on python?

I using next code for facebook for ...READ MORE

answered May 16, 2019 in Selenium by mslavikas@gmail.com
25,583 views
0 votes
2 answers
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,711 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,608 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,680 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,551 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP