gpt4 book ai didi

python - NoSuchElementException : Message: no such element: Unable to locate element while trying to find or access element tags

转载 作者:行者123 更新时间:2023-12-01 08:25:17 30 4
gpt4 key购买 nike

我找不到用户名密码字段。我检查元素,并尝试通过 id、xpath 或 css 选择器查找它,但它给出错误 NoSuchElementException: Message: no such element: Unable to located element.

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time



if __name__ == "__main__":
option = webdriver.ChromeOptions()
option.add_argument("--incognito")
option.add_argument("--start-maximized")

if getattr(sys, 'frozen', False):
chromedriver_path = os.path.join(sys._MEIPASS, "chromedriver.exe")
driver = webdriver.Chrome(chromedriver_path, options=option)
else:
driver = webdriver.Chrome(options=option)

driver.get("https://www.wix.com/")
loginPage = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "/html/body/header/nav/a[2]"))).click()

usernameField = driver.find_element_by_id("input_4")
passwordField = driver.find_element_by_xpath("input_5")

usernameField.send_keys("user")
passwordField.send_keys("pass")
time.sleep(5)
driver.quit()

我得到的错误是:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"id","selector":"input_4"}
(Session info: chrome=71.0.3578.98)
(Driver info: chromedriver=2.44.609538 (b655c5a60b0b544917107a59d4153d4bf78e1b90),platform=Windows NT 10.0.17134 x86_64)

最佳答案

如果您想找到电子邮件密码字段,您可以尝试

usernameField = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "email")))
passwordField = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.NAME, "password")))
usernameField.send_keys("user")
passwordField.send_keys("pass")

找不到字段的原因:

  • driver.find_element_by_id("input_4") - 我没有看到带有 id="input_4" 的元素。 @id 值可能是动态的。
  • driver.find_element_by_xpath("input_5") - "input_5" 不是有效的 XPath 语法。您可能需要使用 //*[@id="input_5"],但无论如何我也没有看到带有 id="input_4" 的元素...

关于python - NoSuchElementException : Message: no such element: Unable to locate element while trying to find or access element tags,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54297309/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com