【发布时间】:2019-09-16 21:52:22
【问题描述】:
我正在尝试通过 Selenium 和 Python 3 从银行的在线服务中每月执行一些繁琐的复制/粘贴操作。不幸的是,我无法让 Selenium 单击登录链接。
这是https://www1.bmo.com/onlinebanking/cgi-bin/netbnx/NBmain?product=5 处的蓝色继续按钮。
奇怪的是,当我尝试在 Selenium 启动的浏览器中手动单击该链接时,它也不起作用 - 而它在我手动启动的浏览器中起作用。
我怀疑问题在于银行的网站足够智能,可以检测到我正在自动执行浏览器活动。有什么办法可以解决吗?
如果不是,会是别的吗?
我尝试过使用 Chrome 和 Firefox - 无济于事。我正在使用带有 Chrome 73.0.3683.103 和 Firefox 66.0 的 64 位 Windows 10 机器。
相关代码如下。
#websites and log in information
bmo_login_path = 'https://www1.bmo.com/onlinebanking/cgi-bin/netbnx/NBmain?product=5'
bmo_un = 'fake_user_name'
bmo_pw = 'fake_password'
#Selenium setup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
chrome_driver_path = 'C:\\Path\\To\\Driver\\chromedriver.exe'
gecko_driver_path = 'C:\\Path\\To\\Driver\\geckodriver.exe'
browswer_bmo = webdriver.Firefox(executable_path = gecko_driver_path)
#browswer_bmo = webdriver.Chrome(executable_path = chrome_driver_path)
#log into BMO
browswer_bmo.get(bmo_login_path)
time.sleep(5)
browswer_bmo.find_element_by_id('siBankCard').send_keys(bmo_un)
browswer_bmo.find_element_by_id('regSignInPassword').send_keys(bmo_pw)
browswer_bmo.find_element_by_id('btnBankCardContinueNoCache1').click()
发送密钥非常有效。我实际上可能有错误的元素 ID(当我意识到我无法手动单击链接时,我试图在 Chrome 中测试它) - 但我认为更大的问题是我无法在启动的浏览器中手动单击链接通过硒。感谢您的任何想法。
编辑
这是我尝试单击继续按钮时得到的所有屏幕截图。
我在 IDE(Jupyter Notebook)中得到的错误信息最终是:
TimeoutException: Message: timeout
(Session info: chrome=74.0.3729.108)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729@{#29}),platform=Windows NT 10.0.17134 x86_64)
【问题讨论】:
-
非常感谢。因为我正在旅行,所以我不得不搁置它,但是一旦我回到家,我就会重新努力并尝试 Selenium IDE 和 Kantu。
标签: python-3.x selenium-webdriver css-selectors webdriver webdriverwait