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 29 in Selenium by Karan
676 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 by Avni

Related Questions In Selenium

0 votes
1 answer
0 votes
1 answer

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

Yes, its very much possible. You just ...READ MORE

answered May 8, 2018 in Selenium by king_kenny
• 3,650 points
7,058 views
+1 vote
2 answers
0 votes
1 answer

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,110 points
1,004 views
0 votes
1 answer
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,130 points
1,151 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
891 views