Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

problem regarding automation using python

ok. Iam trying to autofill google sign.in page using python and selenium. but, im having two problems.

  1. I would like to know if its possible to fill already opened page in the browser instead of opening a new page and filling it.
  2. Whenever im trying to fill the page using the code below, it fills the username but then the browser shows a error saying that couldn't sign in you because the browser or app may not be secure. How to fix this!!
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()
question from:https://stackoverflow.com/questions/65847157/problem-regarding-automation-using-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The error message you are getting implies that the WebDriver was unable to authenticate the Browsing Context i.e. Browser session.

In these cases, the respective solution would be to:

  1. Disable Two Factor Authentification for this Google account and execute your script
  2. Allow less secure apps

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...