Click on second button (identical buttons) Selenium python Click on second button (identical buttons) Selenium python selenium selenium

Click on second button (identical buttons) Selenium python


You can grab references to both elements and just click the second one.

buttons = driver.find_elements_by_css_selector("input.button");buttons[2].click()


Here is the example from the documentation:

<html> <body>  <form id="loginForm">   <input name="username" type="text" />   <input name="password" type="password" />   <input name="continue" type="submit" value="Login" />   <input name="continue" type="button" value="Clear" />  </form></body><html>login_form = driver.find_element_by_xpath("/html/body/form[1]")login_form = driver.find_element_by_xpath("//form[1]")login_form = driver.find_element_by_xpath("//form[@id='loginForm']")

input[1] is an array, starting at 1, so in your case, it should looks like this(Corrected, following comment):

button = driver.find_element_by_xpath("//form[@class='smallfont']/input[@value='Ir'][@type='submit'][2]")button.click()

From:

http://selenium-python.readthedocs.io/locating-elements.html


If I am correct that there is only one submit button in the div of class "smallfont" (the duplicate button is in a different div that does not have that class), then you can simply use a path similar to:

//div[@class='smallfont']/input