Doubt : How to check if a text is highlighted on the page ?

Ques 37) How to check if a text is highlighted on the page ?

1> What does highlighted text means?

<My understanding>  Suppose you browse any page , select any text on that page using mouse or some other means. say “Hello Lakshay” , here is text is highlighted. Please correct my understanding if its wrong.
2> Using the given code: I am getting the Css Value of particular text color.
Would be grateful if you help me in understanding the above concept
Default Asked on April 6, 2015 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)

    Hi Shaktiku,

    Using this api getCssValue we use to get the value of css class properties associated with the element. Lets take example of it

    HTML is like this
    <input id=’but1′ value=’Button with ID’ type=’button’ class=”leftdiv”/>
    <br/><br/><br/>
    <input value=’Sibling Button’ type=’button’/>
    </div>
    <style>
    .leftdiv{ width:100px;height:20px;background-color:linen;text-decoration: underline;font-size:x-small;}
    </style>

    here leftdiv is css class for element type button whose value is “Button with ID”  now its css properties are

    .leftdiv >>>> { width:100px;height:20px;background-color:linen;text-decoration: underline;font-size:x-small;}

    we can pass  different properties in
    driver.findElement(By.id(“but1”)).getCssValue(“text-decoration”) will return “underline”  by this we can verify button text is underline

    driver.findElement(By.id(“but1”)).getCssValue(“font-size”) will return “x-small” by this we can verify that font size of text on button is small.

    Thanks for asking question
    Cheers
    Amit

    Supporter Answered on April 8, 2015.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.