AlexCOM
AlexCOM

Reputation: 129

Find element for Selenium WebDriver

I am just starting to learn Selenium WebDriver. I would like to find This checkbox and click. I can't get it on the straight because it is hidden. Should I get all checkboxes and after it get necessary field?

My code

enter image description here

HTML

enter image description here

Upvotes: 2

Views: 133

Answers (1)

Naveen Kumar R B
Naveen Kumar R B

Reputation: 6398

try using XPATH as follows, to find the element highlighted in underline in the image attached in the question:

By.Xpath("//label[@for='bodystyle-5']")

note: By.name can be used ONLY for name attributes in HTML tags.


To find the HTML corresponding to a Web Element,

  1. Right click on the element you want to find -> select Inspect option in Chrome (Inspect Element in Firefox).

  2. If you want to evaluate XPath or CSS, Follow the steps:

    1. Open Firefox browser
    2. Install Firebug & Firepath plugins to Firefox
    3. Visit your application
    4. Right-click on the element that you want identify, and click on Inspect Element with Firebug option -> takes you to the elements HTML code.

You can try Xpath or CSS selectors in Firepath tab.

Upvotes: 1

Related Questions