0

So I would like to wait for a pop-up and then click Accept. HTML looks like this:

<div class="termsBtn" onclick="checkTerms(0)" style="background-color:#dd4a42">Decline</div>

<div class="termsBtn" onclick="checkTerms(1)" style="background-color:#a6dd42">Accept</div>


I have tried all sorts, but for this current code I am getting a TimeoutException:

selenium.common.exceptions.TimeoutException: Message: 



My current code:

from selenium.webdriver.support import expected_conditions as ec


wait = WebDriverWait(driver, 10)
popup = wait.until(ec.element_to_be_clickable((By.XPATH, '//input[@onclick="checkTerms(1)"]')))
popup.click()

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

There is no input tag of your element it is a div tag.Try below xpath.

wait = WebDriverWait(driver, 10)
popup = wait.until(ec.element_to_be_clickable((By.XPATH, '//div[@class="termsBtn"][text()="Accept"]')))
popup.click()
KunduK
  • 32,888
  • 5
  • 17
  • 41
0

You can use ExpectedConditions.visibilityOfElementLocated, it will wait till the element not visible

Source:

Webdriver How to wait until the element is clickable in webdriver C#

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
0

As the desired element is within a popup so to click() on the element you have to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following solutions:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.termsBtn[onclick*='1']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='termsBtn' and text()='Accept']"))).click()
    
  • 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
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352