1

I have this code: enter image description here

I have a problem clicking a button.

driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]/following::a[1]").click()

And I receive this error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"(.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]/following::a[1]"}
  (Session info: chrome=73.0.3683.86)

Any ideas?

2 Answers 2

0

I'm not an expert in xPath, but my understanding is that

.//*[normalize-space(text()) and normalize-space(.)='Editează'])[20]

will lead you to the 20th element with Editează. In this case, it is already a link (a tag).

Therefore, /following::a[1] will try to find a link inside a link - which leads to a failure.

Maybe only

//a[text()='Editează'][20]

will be enough.

0

If this is the last td of the last tr of the table, I would recommend using

//table/tr[last()]/td[last()]/a[contains(@href,'edit')]

Especially if the website is multilanguage, and you are not trying to check the text of the button, but trying to achieve the edit action

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.