簡體   English   中英

Python:無法找到帶有 id 或類名的元素,webdriver 無法找到 id 或類名

[英]Python: Unable to find element with id or class name, webdriver cannot locate id's or class name's

我正在使用 Selenium 和 Python 創建一個腳本,用於在 Internet Explorer(必須是 IE)中自動執行最終用戶工作流。 使用find_element_by_idfind_element_by_class_name ,我收到NoSuchElementException錯誤。

您能幫我理解為什么我的腳本無法找到元素“ servProvCode ”的 ID 或名稱嗎? 我附上了截圖以提供更多細節。 謝謝!

針對第 23 行返回錯誤:

selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with css selector == [id="submit"]

蟒蛇腳本:

1 import time
2 from selenium import webdriver
3 from selenium.webdriver.common.by import By
4 from selenium.webdriver.common.keys import Keys
5 from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
6
7 #create capabilities
8 capabilities = DesiredCapabilities.INTERNETEXPLORER
9
10 #delete platform and version keys
11 capabilities.pop("platform", None)
12 capabilities.pop("version", None)
13
14 #start an instance of IE
15 driver = webdriver.Ie(executable_path="C:\\LocalDev\\IEDriverServer.exe", capabilities=capabilities)
16
17 #open Accela login page
18 driver.get("https://pwms-avdev.co.arapahoe.co.us/security/hostSignon.do?signOff=true")
19 time.sleep(2)
20
21 #enter Agency
22 agency = driver.find_element_by_id("servProvCode")
23 agency.send_keys('test', Keys.ENTER)
24 time.sleep(2)
25[enter image description here][1]
26 #enter Username

在找到元素之前切換到框架解決了這個問題。

driver.switch_to_frame(0)
agency = driver.find_element_by_id("servProvCode")

參考:

在 selenium web 驅動程序中如何選擇正確的 iframe

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM