4

I just cannot find working way to select this element, tried by CSS and xpath, but nothing works.

<input type="submit" value="Submit">

This does not work:

driver.find_element_by_xpath("//*[@id='theform']/div[2]/input").click()
driver.find_element_by_css_selector(".submit[value='Submit']").click()
2
  • 3
    Try Xpath //input[@type="submit"] or CSS selector input[type="submit"]. If it doesn't work, update your ticket with exception stacktrace Commented Aug 1, 2017 at 19:14
  • This works, thanks Commented Aug 1, 2017 at 19:26

1 Answer 1

9

This does not work:

driver.find_element_by_xpath("//*[@id='theform']/div[2]/input").click() driver.find_element_by_css_selector(".submit[value='Submit']").click()

The first invocation likely does not work because the input descendant node is most likely too vague and ambiguous.

The second invocation doesn't work because .submit[value='Submit'] is searching for (in english)

Any element that has class~="submit" AND value="Submit"

The value attribute matches, but not the class selector.

You could find that element with a quick CSS selector:

driver.find_element_by_css_selector("input[type='submit']")

See Effective CSS Selectors to see how to formulate good CSS selectors, and why this selector above would work.

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

Comments

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.