0

I am trying to use Selenium Webdriver to find and click some buttons. The HTML code is:

<button class="btn param1 param2 param3 param4" na:mode="a.b.c" btn-checkbox="">First</button>
<button class="btn param1 param2 param3" na:mode="a.b.d" btn-checkbox="">Second</button>
<button class="btn param1 param2 param3" ng:mode="a.b.e" btn-checkbox="">Third</button>

I tried to use:

driver.find_element_by_css_selector('button[na:mode="a.b.c"]')

But I get error that says no such element: Unable to locate element

What is the problem with the code I wrote? What is the best way to find these 3 buttons?

1 Answer 1

3

In CSS selector, . (dot) and :(colon) have different meanings. So It needs to be escaped with slash() as given below.

driver.find_element_by_css_selector('button[na\:mode="a\.b\.c"]')
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the answer, I get this error: invalid selector: An invalid or illegal selector was specified
sorry, i forget to escape colon(:) as well. updated the answer.
Great that worked, thank you so much, I upvoted and accepted your answer :)

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.