0

I have this code: enter image description here

Hi , a 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)

Can someone please help me with this one? Thank you

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, privacy policy and cookie policy

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