Home > Back-end >  Finding a submit button with Selenium in Python3
Finding a submit button with Selenium in Python3

Time:01-14

I´m working with a HTML code like this:

<p >Some Text</p><br><p >some
Text<span >
<b><LI>Some headline</LI></b>
<b><LI>Headline of searched button</LI></b>
<form action="qr_info.php" name="1312" method="post">
<INPUT TYPE="submit" NAME="1314" VALUE="Create Ticket">

My code for finding the Button is:

button = driver.find_element(By.XPATH, '//input[@name="1314"]')

or

button = driver.find_element(By.NAME, '1314')

but this doesn´t work. This is the error Code:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"meth oXPathpath","selector":"//input[@name="1314"]"}

Can someone tell me what I´m getting wrong?

CodePudding user response:

The HTML has an input with the attribute of NAME, but your selector is looking for the attribute of name. Making the case the same in your selector may solve your problem.

CodePudding user response:

The name which was shown in the Source Code of the HTML file was not the real name.

I listed up all Names by:

elements = driver.find_elements(By.XPATH, '//*')
    for element in elements:
    print(element.get_attribute('name'))

With that, one can easily get the correct names

  • Related