Click button but multiple classes

Question:

I can click the "AKZEPTIEREN" button using XPATH like this:

WebDriverWait(driver, 15).until(expected_conditions.element_to_be_clickable((By.XPATH, '/html/body/div[4]/div/button[2]'))).click()

To make it more dynamic I want to use a class, so this would be:

WebDriverWait(driver, 15).until(expected_conditions.element_to_be_clickable((By.CLASS_NAME, 'primary.accept.no-pop-execute'))).click()

But the class "primary accept no-pop-execute" is twice on the site. So what can I do to choose the first one?

Page: https://fremdgehen69.com

Button: enter image description here

Asked By: MausHausi

||

Answers:

You can try the below code using xpath expression that will select a single element and click on it because click() method requires a single selection:

WebDriverWait(driver, 15).until(expected_conditions.element_to_be_clickable((By.XPATH, '//*[@class="primary accept no-pop-execute" and contains(., "Akzeptieren")]'))).click()
Answered By: Fazlul
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.