S
S
Shulaishull2021-09-13 01:01:53
Python
Shulaishull, 2021-09-13 01:01:53

Why doesn't selenium find the button by xpath and link_text?

Can't pull element in selenium

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"link text","selector":"Open in window"}


selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="ext-gen956"]"}


613e77eab6fa8813276604.png

driver.find_element_by_id("ext-gen956").click()
driver.find_element_by_xpath("//*[@id="ext-gen956"]").click()
driver.find_element_by_link_text('Открыть в окне').click()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2021-09-13
@vabka

driver.find_element_by_id("ext-gen956").click()
driver.find_element_by_xpath("//*[@id="ext-gen956"]").click()
driver.find_element_by_link_text('Открыть в окне').click()

1st line - everything is ok
2nd line - probably the xpath curve. Well, in this case, the quotes are also crooked
. 3rd line - will not find the element, because it is looking for links, and the specified element is actually a button.
What does AJAX have to do with it, I still don’t understand
UPD : The problem is that this element is inside an iframe.
Although it seems that its content is part of the page, it is not.
You need to switch to it first:
driver.switch_to.frame(driver.find_element_by_css_selector("iframe")) # тут селектор на нужный iframe

Think of an iframe as a separate page/window/tab in the browser that magically renders within the main page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question