我有一個關于硒的問題。
我的點子:
我的想法是制作一個登錄這個網站的Python腳本。Selenium 將用戶名和密碼發送到 HTML 輸入欄位并提交。
問題:
我的代碼一直在說:
Message: no such element: Unable to locate element:
例如,我曾在 google.com 上嘗試過此代碼,并且效果很好。為什么這不適用于此登錄頁面?有人可以幫我嗎?
我的 Python 代碼:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
login_URL = "https://nl.infothek-sptk.com/isps/infothek/?1043"
driver = webdriver.Chrome()
driver.get(login_URL)
time.sleep(5)
inputElement = driver.find_element_by_name('uname')
inputElement.send_keys(username)
time.sleep(20)
driver.close()
uj5u.com熱心網友回復:
我不知道它在 pyton 中是如何作業的,我使用 js 但嘗試使用 xpath driver.find_element_by_xpath('your xpath') [也許再使用 1 次點擊) ('xpath element').click() - 元素處于活動狀態。并在使用后發送密鑰 ******.send_keys('username')
driver.switchTo().frame(driver.findElement(By.xpath('xpath frame'))) - 在 js 中
uj5u.com熱心網友回復:
如前所述,該元素位于iframe. 需要switch to frame與元素進行互動。
最好應用顯式等待。
# Imports required:
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver.get("https://nl.infothek-sptk.com/isps/infothek/?1043")
wait = WebDriverWait(driver,30)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"body_frame")))
wait.until(EC.element_to_be_clickable((By.NAME,"uname"))).send_keys("[email protected]")
# Code to enter other fields.
# Switch back to default to interact with elements outside the iframe.
driver.switch_to.default_content()
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/346960.html
標籤:Python 蟒蛇-3.x 硒 硒网络驱动程序 硒铬驱动器
上一篇:洗掉使用合并資料框創建的列
