1

I'm trying to find this element inside a log-in page when a user inputs the wrong password

<div class="form-input-validation is-error" role="alert"></div>

I have tried

driver.find_element_by_css_selector(".form-input-validation.is-error")

but i get a 'no such element: Unable to locate element' error

4 Answers 4

4

You just can substitute the space by a dot . to get the class.

driver.find_element_by_class_name("form-input-validation.is-error")
Sign up to request clarification or add additional context in comments.

Comments

3

You can find the element using the syntax, it is basically first waiting(using explicit wait) for the element to be located on the page and after that you can operate on it:

WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, "//div[@class='form-input-validation is-error']")))

Note: You have to add the following imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

2 Comments

It would be good to note that using a CSS selector or XPATH doesn't make the difference. The difference here is using an explicit wait.
@GregBurghardt yes, i have updated my answer and provided more explanation to it. Thanks!!
2

Class names can't have spaces, the div tag has two classes (separated by a space, .form-input-validation and is-error). Use one or the other, but I would suggest using .is-error because it will only activate if there is an error.

driver.find_element_by_css_selector(".is-error")

Comments

1

Try replacing the Space with a dot.

driver.find_element_by_class_name("form-input-validation.is-error")

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.