python - Python Selenium 没有这样的元素:无法找到 xpath
问题描述
我正在尝试自动登录到我是用户的投注网站,但我无法完成登录,因为 selenium 找不到 xpath。这是我到目前为止使用的代码:
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import login_data
def main():
options = webdriver.ChromeOptions()
options.headless = False
options.add_experimental_option("excludeSwitches", ["enable-logging"])
browser = webdriver.Chrome(options=options, executable_path=r'C:\Users\bilakos\Documents\DRIVERS\chromedriver.exe')
browser.get("https://en.stoiximan.gr/")
sleep(5)
login_data.login(browser)
main()
这是导入代码:
def login(browser):
username = 'Username'
password = 'password'
#Here is the first login button that is needed to be clicked before i'm gonna enter my data
login = browser.find_element_by_xpath("""//*[@id="landing-page-modal"]/div/div[2]/div[1]/p[2]/a""")
login.click()
sleep(5)
#Here is the place i enter my username
username_input = browser.find_element_by_xpath("""//*[@id="js-login-form"]/div[1]/div[1]/input""")
username_input.click()
username_input.send_keys(username)
#Here is the place i enter my password
password_input = browser.find_element_by_xpath("""//*[@id="js-login-form"]/div[2]/div[1]/input""")
password_input.click()
password_input.send_keys(password)
#Here i'm clicking the login button to login to my account
login_button = browser.find_element_by_xpath("""//*[@id="js-login-button"]""")
login_button.click()
这是我得到的错误:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="js-login-form"]/div[2]/div[1]/input"}
(Session info: chrome=87.0.4280.88)
用户名和密码 xpath 都会出现问题。如果有人有解决方案,我将不胜感激。
该网站的链接是: https ://en.stoiximan.gr/
解决方案
推荐阅读
- javascript - chart.js 绘制时间序列
- c# - 如何使用取决于日期的价格总和进行实体框架查询?
- visual-studio-code - VS Code 格式化插件
- javascript - 循环一个没有 HTML 文件的公共图像目录
- javascript - 如何在没有 es6 的情况下在 javascript 中进行插值
- python - 制作 discord.py 聊天过滤器,给出错误“await”是无效语法
- java - 在使用 Junit 进行测试期间,@Autowired 字段为空,我如何模拟/实例化它?
- c++ - Rcpp:关于赋值基本操作的混淆
- python - 从给定的整数列表中返回差为 2 的所有整数对
- python - 在 sphinx-autodoc 中对成员进行不区分大小写的排序