S
S
sergey prohorenko2020-05-16 21:35:40
Python
sergey prohorenko, 2020-05-16 21:35:40

Throws an error when trying to select elements with Selenium for Python?

here is the code:

driver.find_element_by_xpath("//*[@id="courses"]/tbody/tr[12]/td[3]/a").click()

here is the error:

driver.find_element_by_xpath("//*[@id="courses"]/tbody/tr[12]/td[3]/a").click()                                ^
SyntaxError: invalid syntax


I understand that the problem is because of the line in xpath: ( [@id="courses" )
but if this line is removed, the code starts. but no action is taken.
also tried other methods. doesn't matter. the error pops up. does not find the element.
html button code:5ec031054205b309559611.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Yakushenko, 2020-05-16
@prohorenko007

Because you have double quotes in double quotes. They must either be escaped or written like this: '//*[@id="courses"]/tbody/tr[12]/td[3]/a'
Read at least about the syntax, or something.
And yes, why are you using selenium if you control it through pyautogui anyway? Why methods like send_keys did not please you?
PS The code is not allowed to spread in the form of screenshots, only the text wrapped in a special tag.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question