Reputation: 225
I'm using the following code to click a button on a page but the XPath keeps changing so the code keeps breaking:
mydriver.find_element_by_xpath("html/body/div[2]/div[3]/div[1]/div/div[2]/div[2]/div[4]/div/form[2]/span/span/input").click()
Is there a better way I should be doing this? Here is the code for the button I am trying to click:
<input class="a-button-input" type="submit" title="Button 2" name="submit.button2-click.x" value="Button 2 Click"/>
Upvotes: 0
Views: 552
Reputation: 3781
XPath is really intelligent. You could do a much more simple search for that:
mydriver.find_element_by_xpath("//input[@name='submit.button2-click.x']")
which tells: search all input
elements whose name
equals to 'submit.button2-click.x'
which will be the element of your choice.
Don't forget to try Firefix XPath Checker add-on before going to code.
Upvotes: 1
Reputation: 815
I'd use findelement(by.name(" submit.button2-click.x")).click() or use find element(by.cssSelector("selector ")).click()
Upvotes: 1