Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Click button but multiple classes

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Page: https://fremdgehen69.com

Button: enter image description here

>Solution :

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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading