栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用Selenium处理Google Authenticator

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用Selenium处理Google Authenticator

这是将读取Google身份验证器令牌并在登录中使用的代码。使用js打开新标签页。

pyotp
在运行测试代码之前安装软件包。

pip安装pyotp

测试代码:

from pyotp import *from selenium import webdriverfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.common.by import Bydriver = webdriver.Firefox()driver.get("https://sellercentral.amazon.de/listing/download?ref=ag_dnldinv_apvu_newapvu")wait = WebDriverWait(driver,10)# enter the emailemail = wait.until(EC.presence_of_element_located((By.XPATH, "//input[@name='email']")))email.send_keys("email goes here")# enter passworddriver.find_element_by_xpath("//input[@name='password']").send_keys("password goes here")# click on signin buttondriver.find_element_by_xpath("//input[@id='signInSubmit']").click()#wait for the 2FA feild to displayauthField = wait.until(EC.presence_of_element_located((By.XPATH, "xpath goes here")))# get the token from google authenticatortotp = TOTP("secret goes here")token = totp.now()print (token)# enter the token in the UIauthField.send_keys(token)# click on the button to complete 2FAdriver.find_element_by_xpath("xpath of the button goes here").click()# now open new tabdriver.execute_script("""window.open("https://sellercentral.amazon.de/listing/download?ref=ag_dnldinv_apvu_newapvu")""")# continue with your logic from here


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/391027.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号