我正在创建一个简单的Python代码来检查网站上的密钥。 我有这个问题,我不知道如何解决:/
我已经尝试过WebDriverWait,但仍然遇到相同的问题。
from selenium import webdriver
#from selenium.webdriver.common.by import By
#from selenium.webdriver.support.ui import WebDriverWait
#from selenium.webdriver.support import expected_conditions as EC
import time
from bs4 import BeautifulSoup
driver = webdriver.Firefox()
driver.get("mywebsite")
boxKey = driver.find_element_by_name("tokenString")
boxKey.send_keys(key)
time.sleep(1)
element = driver.find_element_by_id("nextButton")
print(element.is_enabled())
这不是完整的代码,只是有趣的部分
Traceback (most recent call last):
File "C:\Users\user\Documents\Check\check.py", line 54, in <module>
check(line)
File "C:\Users\user\Documents\Check\check.py", line 45, in check
boxKey = driver.find_element_by_name("tokenString")
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 496, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\user\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: [name="tokenString"]```