1

I have these following elements in a page and I need to select the element with the value 18 inside using Python and selenium script. That is the second link. Here is the HTML code of the page

<a class="ui-state-default ui-state-highlight ui-state-active" href="#">17</a>
<a class="ui-state-default ui-state-highlight ui-state-active" href="#">18</a>
<a class="ui-state-default ui-state-highlight ui-state-active" href="#">19</a>

I am trying to use the following Python and Selenium code to click

elem = driver.find_element_by_xpath('//a[@class="ui-state-default"]').click()

But that does not work. How do I fix it?

2 Answers 2

1
elem = driver.find_element_by_link_text("18")
elem.click()
Sign up to request clarification or add additional context in comments.

Comments

1

That will find the first element matching that XPath, which is the one with the value 17. To select the element whose value is 18, try this:

driver.find_element_by_link_text('18').click()

PS: You don't need to set the click event to a variable. Only do this if you need to multiple actions on the element (send_keys(), click(), text, etc.)

Comments

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.