Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何使用Selenium和Python单击Continue按钮_Python 3.x_Selenium Webdriver_Css Selectors_Webdriver_Webdriverwait - Fatal编程技术网

Python 3.x 如何使用Selenium和Python单击Continue按钮

Python 3.x 如何使用Selenium和Python单击Continue按钮,python-3.x,selenium-webdriver,css-selectors,webdriver,webdriverwait,Python 3.x,Selenium Webdriver,Css Selectors,Webdriver,Webdriverwait,我正试图通过Selenium和Python3自动化我每月从银行的在线服务进行的一些繁琐的复制/粘贴。不幸的是,我无法让Selenium单击登录链接 是蓝色的“继续”按钮 奇怪的是,当我试图在Selenium启动的浏览器中手动单击该链接时,它也不起作用——而在我手动启动的浏览器中它确实起作用 我怀疑问题在于银行网站足够聪明,可以检测到我正在自动执行浏览器活动。有没有办法绕过这个问题 如果不是,可能是别的什么吗 我试过使用Chrome和Firefox,但都没有用。我使用的是一台64位Windows1

我正试图通过Selenium和Python3自动化我每月从银行的在线服务进行的一些繁琐的复制/粘贴。不幸的是,我无法让Selenium单击登录链接

是蓝色的“继续”按钮

奇怪的是,当我试图在Selenium启动的浏览器中手动单击该链接时,它也不起作用——而在我手动启动的浏览器中它确实起作用

我怀疑问题在于银行网站足够聪明,可以检测到我正在自动执行浏览器活动。有没有办法绕过这个问题

如果不是,可能是别的什么吗

我试过使用Chrome和Firefox,但都没有用。我使用的是一台64位Windows10机器,带有Chrome73.0.3683.103和Firefox66.0

相关代码如下

#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()
发送钥匙非常有效。当我意识到我不能手动点击链接时,我可能实际上在Chrome中测试的元素ID是错误的,但我认为更大的问题是我不能手动点击Selenium启动的浏览器中的链接。谢谢你的建议

编辑

这是一个屏幕截图,当我尝试单击“继续”按钮时,我得到了所有的截图

最终,我在IDE Jupyter笔记本中得到的错误消息是:

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)

要在按钮上单击文本“继续”,您可以填写卡号和密码字段,使元素可单击,并且可以使用以下解决方案:

代码块:

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

options = webdriver.ChromeOptions()
options.add_argument('start-maximized')
options.add_argument('disable-infobars')
options.add_argument('--disable-extensions')
driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\WebDrivers\chromedriver.exe')
driver.get('https://www1.bmo.com/onlinebanking/cgi-bin/netbnx/NBmain?product=5')
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.dijitReset.dijitInputInner#siBankCard[name='FBC_Number']"))).send_keys("1234567890112233")
driver.find_element_by_css_selector("input.dijitReset.dijitInputInner#regSignInPassword[name='FBC_Password']").send_keys("fake_password")
driver.find_element_by_css_selector("span.dijitReset.dijitInline.dijitIcon.dijitNoIcon").click()
# driver.quit()
浏览器快照:


我可以通过在选项变量下面添加以下行来解决这个问题。这将禁用chrome自动检查。在启动驱动程序之前,我使用了整个销售代码,然后在正确的位置添加了以下行

options.add_experimental_option("excludeSwitches", ['enable-automation'])


参考:谢谢!不幸的是,当我尝试大量使用您的代码时,仍然会以编程方式或手动方式得到一个不可点击的按钮。可能是因为今天早上我无意中将Chrome更新为74.0.3729.108,当时Chrome给了我这个选项?@PKB不知道为什么你会得到不可点击的按钮,但是使用ChromeDriver和Chrome的兼容版本,这个代码块工作得非常完美。我也这么认为。我仍然能够让代码运行到填充字段的程度,但是页面拒绝加载。Selenium给了我一个超时,但Chrome似乎只是无限期地旋转,我让它旋转了20多分钟而没有超时。我承认我是一个初学者,所以我将尝试解析HTML,弄清楚你在用CSS_选择器做什么,也许这会给我一些想法。再次感谢。作为一名初学者,您能否复制粘贴我答案中的代码,并使用兼容版本的ChromeDriver和Chrome回复我的状态?谢谢,我再试了一次。我已经用截图编辑了我的文章,截图是我用你的代码得到的。我所改变的只是更新的Chromedriver的路径。非常感谢。我不得不暂时搁置,因为我正在旅行,但一旦我回到家,我将恢复我的努力,并尝试硒IDE和Kantu。