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
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()
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
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()