0

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"/>

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

I'd use findelement(by.name(" submit.button2-click.x")).click() or use find element(by.cssSelector("selector ")).click()

1 Comment

Thanks for the reply. This also works mydriver.find_element_by_name("submit.button2-click.x").click()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.