K
K
kercha2020-12-16 00:47:30
XPath
kercha, 2020-12-16 00:47:30

Unable to find element by xpath using selenium. Any thoughts?

Faced the following problem. You need to find the element and click on it. The problem is the following: the web is built on Ember.js, so each element has a dynamic id. I tried to find an element by text in the class, but it still fails.

part of the website code:

<a href="javascript:void(0)" class="link" data-ember-action="" data-ember-action-574="574">Зарегистрироваться</a>


My code:

registration = browser.find_element_by_xpath('//*[@class='link' and text()='Зарегистрироваться']').click()


Rummaged through Google, someone says that it is generally impossible to test applications built on Ember, someone offers a fierce game with a search for the full xpath path, which does not work either.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Sundukov, 2020-12-16
@kercha

//*[contains(@class, "link")][contains(text(), "Зарегистрироваться")]

In addition, the element may not be in the DOM at the time of the request, so you must first do wait.until(visibility_of_element_located) like this: How to wait for elements in Python Selenium WebDriver

S
Sergey Karbivnichy, 2020-12-16
@hottabxp

Today they brought an article to Habr, look, it can help - XPath functions for dynamic XPath in Selenium

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question