2

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

5
  • Share your code and HTML as text, not as images. Also add exception log if you got any Commented Feb 9, 2017 at 12:35
  • bodies id is set to div did you want to select url inside that? Commented Feb 9, 2017 at 12:35
  • No i would like yo get all of the checkboxes. I think i should have to used class="unstyle boxed bu-list-three-colums" Commented Feb 9, 2017 at 12:39
  • Your code contains By.Name(bodystyle-4) and I can not see such element! Commented Feb 9, 2017 at 12:44
  • Sorry guys, i don't know what elements i should use, so i added test data to my code. Commented Feb 9, 2017 at 12:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot! It's working. CCan you explain me when should i use for to get all of the fields?
I used @for='bodystyle-5' because, HTML code contains for attribute. General syntax is //tag[@attributeName=attributeValue]. so, you can use any attribute in HTML like name, value, id, class etc.
but how can i get it not using the xPath?
0other option is CSS selectors. apart from it, there is NO direct way to find. If you have any of ID, name, class name, link text, tag name then you can find directly using corresponding By. methods.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.