【问题标题】:problem regarding automation using python关于使用python自动化的问题
【发布时间】:2021-01-22 14:35:42
【问题描述】:

好的。我正在尝试使用 python 和 selenium 自动填充 google sign.in 页面。但是,我有两个问题。

  1. 我想知道是否可以在浏览器中填充已打开的页面,而不是打开一个新页面并填充它。
  2. 每当我尝试使用下面的代码填充页面时,它会填充用户名,但随后浏览器会显示错误消息couldn't sign in you because the browser or app may not be secure。如何解决这个问题!
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
chromedriver = 'd:Drivers\\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
browser.get('https://accounts.google.com/ServiceLogin/identifier?flowName=GlifWebSignIn&flowEntry=AddSession')
args: ['--disable-web-security', '--user-data-dir', '--allow-running-insecure-content' ]
username = browser.find_element_by_xpath('//*[@id="identifierId"]')
username.send_keys("")
browser.find_element_by_xpath('//*[@id="identifierNext"]/div/button/div[2]').click()
time.sleep(3)
password = browser.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
password.send_keys(" ")
browser.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div/div[2]/div/div/div[2]/div/div[2]/div/div[1]/div/div/button/div[2]').click()

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver selenium-chromedriver


    【解决方案1】:

    您收到的错误消息表明 WebDriver 无法验证浏览上下文,即浏览器会话。

    在这些情况下,相应的解决方案是:

    1. 为此 Google 帐户禁用双重身份验证并执行您的脚本
    2. Allow less secure apps

    【讨论】:

      猜你喜欢
      • 2020-09-13
      • 2016-06-24
      • 1970-01-01
      • 2019-12-16
      • 2011-05-25
      • 1970-01-01
      • 1970-01-01
      • 2020-12-16
      • 2018-10-04
      相关资源
      最近更新 更多