Mateo
Mateo

Reputation: 158

How to click on a pop-up button with Selenium using Python

I want to click on a popup window but after trying several ways, I obtain a "TimeoutException" error.

This is the code that I'm trying:

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='modal-footer modal-footer-gallit-postula' and @id='modal_comentarios']"))).click()

And I attach an image of the htmlenter image description here

For further information, the popup is very similar to the one appearing in the url below after clicking on the green button that says "Postular" (to get the exact popup it's necessary to be logged in). https://trabajo.gallito.com.uy/anuncio/vendedor-automotriz-qm995

Upvotes: 0

Views: 1360

Answers (2)

Potato
Potato

Reputation: 99

You can use time.sleep() to handle this. For context:

    from selenium import...
    import time

    driver.get(url)
    butn = driver.find_element(by=By.XPATH, value='//* 
    [@id="postular"]').click() 
    time.sleep(5)
    driver.find_element(by=By.XPATH, value='____').click()

-I don't have the credentials to login, but this is how i handle modal alerts

Upvotes: 0

undetected Selenium
undetected Selenium

Reputation: 193088

The desired element is within a Modal Dialog Box so to click on the clickable element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.modal-footer.modal-footer-gallit-postula > button.btn.btn-primary.btn-color-postula"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-primary btn-color-postula' and text()='Aceptar']"))).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
    

Upvotes: 1

Related Questions