1

Is there a way to use driver.find_element(By.XPATH, ...) to find an element specifying NOT ONLY its class, but also the class value?

I know this:

driver.find_element(By.XPATH, "//*[@class='class_value'")

But how can I add the value filter?

1
  • Please edit your question and update with relevant HTML and your expected output? Commented Sep 14, 2022 at 8:10

1 Answer 1

2

Sure, you can locate elements by any attributes including any possible combinations of them.
So, to locate element based on it class name attribute value and value attribute value it can be something like this

driver.find_element(By.XPATH, "//*[@class='class_value' and @value='value_value']")

In case there are other class attribute values or / and value attribute values we can use contains as following

driver.find_element(By.XPATH, "//*[contains(@class,'class_value') and contains(@value,'value_value')]")

Or (the same as above, just different syntax)

driver.find_element(By.XPATH, "//*[contains(@class,'class_value')][contains(@value,'value_value')]")
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.