我正試圖讓Selenium按下這個頁面上的下載按鈕。
我一直在嘗試使用
mod = browser.find_element_by_css_selector('#method_free').click()
但是我得到了錯誤
selenium.common.exceptions.NoSuchElementException: 訊息:沒有這樣的元素。無法定位元素。
uj5u.com熱心網友回復:
你基本上需要明確的等待,因為HTML DOM中的id是唯一的。
driver = webdriver.Chrome(driver_path)
driver.maximum_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()
匯入 :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
注意,一旦你點擊了下載,一個新的標簽正在打開,要與該新視窗中的網路元素互動,你需要切換。
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1] )
然后你就可以與新的視窗專案進行互動。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/309732.html
標籤:
