Search code examples
pythonseleniumpycharmselenium-chromedriver

unable to loacate in selelium python {"method":"css selector","selector":"[id="downloadButton"]"} (Session info: chrome=98.0.4758.102)


This is my code and it only opens chrome.Does not click on button id that i gave.CAn anyone please help me with this.

import os
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
os.environ['PATH'] += r"C:/SeleniumDriver"
driver = webdriver.Chrome()
WebDriverWait(driver, 10)
driver.get("https://jqueryui.com/progressbar/#download")
my_element = driver.find_element(By.ID, 'downloadButton')
my_element.click()

Solution

  • The button is inside of an iframe, in which case you have first switch to the iframe and then access the element inside of it.

    WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH, "//iframe")))
    driver.find_element(By.ID, "downloadButton").click()
    

    imports:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC