I am trying to get selenium to press the download button on this page.
I've been trying to use
mod = browser.find_element_by_css_selector('#method_free').click()
but I get the error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:
CodePudding user response:
You need basically explicit waits, cause the id in HTML DOM is unique.
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
wait = WebDriverWait(driver, 20)
driver.get("https://modsbase.com/yjdfcs34gxix/1863514508_BetterCheats.zip.html")
wait.until(EC.element_to_be_clickable((By.ID, "method_free"))).click()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Note that once you click
on the download
a new tab
is opening up, to interact with the web element in that new window
, you'd need to switch.
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
and then you can interact with new windows item.