https://www.bccard.com/app/merchant/Login.do
我正在尝试使用Python Selenium自动登录此站点。但是,正如您可能注意到的,密码输入位置没有接收driver.send_keys
代码:
from selenium import webdriver
import time
driver = webdriver.Chrome('C:/chromedriver/chromedriver.exe')
driver.get('https://www.bccard.com/app/merchant/Login.do')
time.sleep(2)
alert = driver.switch_to_alert()
alert.dismiss()
driver.find_element_by_xpath('//*[@id="userid"]').send_keys('id')
driver.find_element_by_xpath('//*[@id="passwd"]').send_keys('pw')
您的代码对我来说很好,只需切换:
为此:
至少对我来说,
switch_to_alert()
在Pycharm中已被弃用并出现错误除了用户ID和密码之外,请填写好
1在发送了一定数量的自动请求后,站点开始阻止这些请求。我添加了一个关于如何避免机器人检测的选项。在这方面寻找类似的问题
2您可以等待警报并检查其中的文本
3不要使用时间。睡眠,使用隐式/显式等待 第2点和第3点是代码中的主要问题
更新和解决方案
我发现,经过多次尝试后,您开始使用虚拟键盘。因此,您可以使用Javascript绕过它:
而不是
您可以引入显式等待以获得更高的稳定性。以下代码适用于我:
相关问题 更多 >
编程相关推荐