我正在嘗試一些硒程式,但現在我一直無法登錄。
- 這是代碼=> https://pastebin.com/ykTcd1rb
- 當代碼執行最后一行代碼時(
username = driver.find_element(By.ID, 'Login'))我得到一個錯誤(selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="Login"]"}) - 這是我試圖得到的元素
<input aria-invalid="false" type="text" name="Login" id="Login" required="">
請幫我
uj5u.com熱心網友回復:
如我所見,more = driver.find_element(By.ID, "dropdownTopRightMenuButton")由于該元素不可見,因此無法執行此命令。
此外,使用硬編碼的睡眠也不是一個好主意。WebDriverWait expected_conditions應改為使用。
以下代碼對我有用:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
options = Options()
options.add_argument("start-maximized")
webdriver_service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=webdriver_service)
wait = WebDriverWait(driver, 10)
url = "https://portal.librus.pl/rodzina/synergia/loguj"
driver.get(url)
wait.until(EC.element_to_be_clickable((By.ID, "cookieBoxClose"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.login-before-btn"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='email']"))).send_keys("my_username")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "[name='password']"))).send_keys("my_password")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button[type='submit']"))).click()
這當然是因為我沒有有效的憑據而無法登錄,但是使用正確的憑據應該可以
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/512216.html
標籤:Python硒硒网络驱动程序css 选择器网络驱动程序等待
上一篇:無法在“Chrome://”之類的頁面中發送密鑰-SeleniumJava
下一篇:org.openqa.selenium.NoSuchElementException:沒有這樣的元素(按索引切換到幀)
