0

while I was trying to automate the web browser, I used click method at the end to click the button, I gave button Id to find element but its opening the new automated browser but not clicking on "Start Download" button. I am getting no errors. My code is given below.

from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import time

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
driver.get("https://jqueryui.com/resources/demos/progressbar/download.html")
time.sleep(20)
my_element = driver.find_element(By.ID, "downloadButton")
my_element.click()

I tried click method to call the download button but its not working properly.

Anas
  • 21
  • 1
  • 2

2 Answers2

0

reason for this issue could be that the download button may not be ready to be clicked when the click() method is being called. you can try using the WebDriverWait class to wait for the button to become clickable before clicking it.

my_element = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "downloadButton")))

my_element.click()
Lakshitha Samod
  • 383
  • 3
  • 10
0

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:

    driver.get("https://jqueryui.com/resources/demos/progressbar/download.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#downloadButton"))).click()
    
  • Using XPATH:

    driver.get("https://jqueryui.com/resources/demos/progressbar/download.html")
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='downloadButton']"))).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