“NoSuchElementException”尽管尝试使用 Selenium 和 Python 的 XPATH、NAME、CLASS_NAME

问题描述 投票:0回答:1

我使用 selenium 和 Python 3.7,chrome 驱动程序版本 124.0.6367.91。 在 Smartplay 的网页上,我本质上是在尝试自动填写用户名和密码。

对于如何在两个字段中输入我的用户名/密码有什么建议吗?

我已经尝试过以下方法,但每次都会导致

NoSuchElementException: Message: no such element: Unable to locate element

driver.find_element(By.NAME,"pc-login-username").send_keys(username)
driver.find_element(By.CLASS_NAME,"input").send_keys(username)
driver.find_element(By.XPATH, "/html/body/div[@id='app']/div[@class='app-router-view']/div/div[1]/div[@class='smart-play-pc-tablet']/div/div[@class='home-pc-head']/div[@class='home-pc-head-box']/div[@class='my-input el-input']/input[@class='el-input__inner']").send_keys(username)

我什至尝试等待该元素出现,但它似乎从未加载到页面上:

try:
   myElem = WebDriverWait(driver, 10).until(EC.presence_of_element_located(By.NAME,"pc-login-username")
   print ("Element is present")
except TimeoutException:
   print ("Element not found")
python selenium-webdriver
1个回答
0
投票

他们在该网站上有很多机器人保护,包括阻止您检查元素,当您导航到 URL 时,它会将您从网站上弹出。这是它找不到元素的主要原因......因为它最终出现在空白页面上。

© www.soinside.com 2019 - 2024. All rights reserved.