1

I want to locate an element in selenium using css selector, and I use the program "copy css selector" and got:

div>button[type ="submit"]

Is this correct?

submit_button = driver.find_element_by_css_selector("input[type='submit']")
1
  • 1
    You might want to provide a bit more information. What language and libraries are you using? Python? JS? Java? what versions? I assume the "copy css selector" is in Chrome or some similar browser. I'm pretty sure stackoverflow quality police are going to mark your question as lacking research, so do a bit of search in stackoverflow and you should find the answer. e.g. stackoverflow.com/questions/18288333/… You may find if there is more than one button on your page you may get more than one match for "submit" though. Commented Jan 10, 2021 at 19:42

1 Answer 1

3

Yes, the Locator Strategy below:

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

is syntactically correct. But as per the copy css selector it should have been:

submit_button = driver.find_element_by_css_selector("div > button[type='submit']")

Note: find_element_by_* commands are deprecated. Please use find_element() instead

Accordingly you can also use:

submit_button = driver.find_element(By.CSS_SELECTOR, "input[type='submit']")

As per copy css selector:

submit_button = driver.find_element(By.CSS_SELECTOR, "div > button[type='submit']")
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.