Forum Discussion

abhishek1997's avatar
abhishek1997
Contributor
2 years ago

How to verify if a web element is selected or not

Hello Team,

 

How to verify if a web element is selected or not. For example, see the attached screenshot. If Button A is clicked Label A will be selected. So we have to verify the whether Label A is selected or not.

 

I have searched in TestComplete Documentation, unlike selenium there is isSelected() method, but I did not find anything like that with TestComplete. Could you please help me regarding this question ??

  • I tried in different way, it worked for me

     

    def isSelected():
    ele = homePage.FindElement("xpath")
    eleClass = str(ele.getAttribute("class"))
    if "highlighted" in eleClass :
    Log.Message("The element is selected")
    else:
    Log.Message("The element is not selected")

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    Use the Object Spy tool and compare each of the properties and property values, for the item that's selected and not selected. That should give you an indication as to what property you should use to indicate that the item is selected.

     

    Also, if selection is made using CSS, then refer to Getting CSS Attributes

    • abhishek1997's avatar
      abhishek1997
      Contributor

      I tried, when the web element is selected, the background color is grey, but when I used CSS attributes, it is retrieving the background color as white, I wanted to verify whether the web element is selected or not.

       

  • rraghvani's avatar
    rraghvani
    Champion Level 3

    In this example,

    The cursor is focused on the First name edit box, and the edit box has a slightly thicker out-line than Last name edit box. It's not possible to check this, as there's no attribute that defines the selection, as it's rendered by the browser.

    • abhishek1997's avatar
      abhishek1997
      Contributor

      I tried in different way, it worked for me

       

      def isSelected():
      ele = homePage.FindElement("xpath")
      eleClass = str(ele.getAttribute("class"))
      if "highlighted" in eleClass :
      Log.Message("The element is selected")
      else:
      Log.Message("The element is not selected")