![](/img/trans.png)
[英]How to click in an input element in a HTML using Selenium with Python 3.8
[英]Can't click on an input element HTML using Selenium for Python
我在 Python 上使用 Selenium 時遇到問題。 這是整個錯誤代碼:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"/html/body/div/div[3]/div[2]/form[1]/input"}
(Session info: MicrosoftEdge=89.0.774.57)
這是我要訪問的元素:
事實是,當我單擊該元素並復制完整的 XPath 時,這就是我所擁有的:
/html/body/div/div[3]/div[2]/form[1]/input
但由於某些原因它不起作用......我幾乎嘗試了所有方法:使用名稱,使用值,使用正常的 XPath(即//*[@id="content"]/form[1]/input
順便一提)
我正在使用 Edge Chromium,我使用 Python 3.9.0,這是我正在使用的代碼(在變量telechargerReleve
之前一切正常:
from selenium import webdriver
driver = webdriver.Edge(executable_path="automation_drivers/msedgedriver.exe")
driver.get("https://login.unice.fr/login?service=https://ent.unice.fr/uPortal/Login")
usernameElement = driver.find_element_by_id("username")
passwordElement = driver.find_element_by_id("password")
usernameElement.send_keys("myUsername")
passwordElement.send_keys("myPassword")
login = driver.find_element_by_name("submit")
login.click()
mesInfos = driver.find_element_by_xpath("/html/body/table[2]/tbody/tr/td[3]/table/tbody/tr[2]/td[3]/a")
mesInfos.click()
intracursus = driver.find_element_by_xpath("/html/body/table[3]/tbody/tr/td[2]/span[2]/a[3]")
intracursus.click()
telechargerReleve = driver.find_element_by_xpath("/html/body/div/div[3]/div[2]/form[1]/input")
telechargerReleve.click()
提前謝謝你,魯。
PS:有些文字可能是法語,所以如果您需要翻譯或其他內容,請隨時問我!
好的,所以我弄清楚了問題所在。 該網站在 HTML 中使用了iframe
標簽作為按鈕,這顯然是我無法單擊它的主要原因。 我在我的代碼中編輯的是我替換為的最后兩行:
seq = driver.find_elements_by_tag_name('iframe')
for index in range(len(seq)):
driver.switch_to_default_content()
iframe = driver.find_elements_by_tag_name('iframe')[index]
driver.switch_to.frame(iframe)
try:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME,"telrelevepresences"))).click()
except TimeoutException:
pass
謝謝大家的回答!
在您單擊 a 標簽后引發等待。
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME,"telrelevepresences"))).click()
進口
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.