1

So I'm writing a script using Selenium but I got stuck at finding a div class.

The structure on the website is like this:

<div class="field first_name">
    <input type="text" placeholder="First Name"></input>
</div>`

Already tried something like driver.find_element_by_xpath("//field[@first_name]") But it didn't work for some reason, maybe I did it wrong or have to it in a different way.

Anyone got a clue?

1 Answer 1

12

You are mixing class and xpath locators in an unsupported way!

Either of the following will work:

driver.find_element_by_xpath("//div[contains(@class, 'first_name')]")
driver.find_element_by_class_name("first_name")

You might want to consider reading some documentation on XPath, and perhaps Selenium locators in general.

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

1 Comment

Thank you very much friend for both the solution and documentation links.

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.