我有这个Selify脚本,它可以输入邮箱地址,点击Use Password按钮,但输入密码失败:

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

web = webdriver.Chrome()
web.implicitly_wait(5)
web.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=16&ct=1700481689&rver=7.0.6738.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fcobrandid%3dab0455a0-8d03-46b9-b18b-df2f57b9e44c%26nlp%3d1%26deeplink%3dowa%252f%26RpsCsrfState%3de98b3d70-89d0-6e78-6a87-b7d5b1245a4e&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=ab0455a0-8d03-46b9-b18b-df2f57b9e44c')

EmailSignIn = web.find_element(By.XPATH,"//*[@id='i0116']")
EmailSignIn.send_keys("generic@live.com")

web.implicitly_wait(5)

EMailSignInContinueButton = web.find_element(By.XPATH, "//*[@id='idSIButton9']")
EMailSignInContinueButton.click()

web.implicitly_wait(5)

UsePasswordButton = web.find_element(By.XPATH, "//*[@id='idA_PWD_SwitchToPassword']")
UsePasswordButton.click()

web.implicitly_wait(5)

SelectEMailPasswordBox = web.find_element(By.XPATH,"//*[@id='i0118']")
SelectEMailPasswordBox.send_keys("FakePassword")

time.sleep(5)

我对脚本的其余部分没有任何问题,所以我在想,密码框肯定有什么新奇的地方,我不知道?其他在线信息似乎已经过时.感谢您的帮助,谢谢!

try 如上所述运行脚本,输入密码失败.希望在Outlook中填充密码.

推荐答案

Root cause of the issue:不需要下面这条线.我在属性为ID=idA_PWD_SwitchToPassword的HTML中看不到任何内容.(102)

UsePasswordButton = web.find_element(By.XPATH, "//*[@id='idA_PWD_SwitchToPassword']")
UsePasswordButton.click()

Check the below working refactored code:

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

web = webdriver.Chrome()
web.maximize_window()
web.get('https://login.live.com/login.srf?wa=wsignin1.0&rpsnv=16&ct=1700481689&rver=7.0.6738.0&wp=MBI_SSL&wreply=https%3a%2f%2foutlook.live.com%2fowa%2f%3fcobrandid%3dab0455a0-8d03-46b9-b18b-df2f57b9e44c%26nlp%3d1%26deeplink%3dowa%252f%26RpsCsrfState%3de98b3d70-89d0-6e78-6a87-b7d5b1245a4e&id=292841&aadredir=1&CBCXT=out&lw=1&fl=dob%2cflname%2cwld&cobrandid=ab0455a0-8d03-46b9-b18b-df2f57b9e44c')
wait = WebDriverWait(web,15)

EmailSignIn = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='i0116']")))
EmailSignIn.send_keys("generic@live.com")

EMailSignInContinueButton = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id='idSIButton9']")))
EMailSignInContinueButton.click()

SelectEMailPasswordBox = wait.until(EC.element_to_be_clickable((By.XPATH,"//*[@id='i0118']")))
SelectEMailPasswordBox.send_keys("FakePassword")

time.sleep(20)

Result:

enter image description here

Python-3.x相关问答推荐

我的SELECT函数搜索的是列,而不是列中的数据.我怎么才能让它搜索数据呢?

PythonPandas 创建一个列并添加到DataFrame

以编程方式关闭jupyterlab内核

基于另一个数据帧计算总和

合并两个数据帧并对某些总和进行求和

Python 舍入数字不准确

裁剪复数以解决 exp 中的溢出错误

如何在两个矩阵的比较中允许任何列的符号差异,Python3?

UnicodeDecodeError:utf-8编解码器无法解码位置 1 的字节 0x8b:无效的起始字节,同时读取Pandas中的 csv 文件

运行 PyCharm 测试时如何解决django.core.exceptions.ImproperlyConfigured:找不到 GDAL 库?

Generic[T] 基类 - 如何从实例中获取 T 的类型?

使用自定义比较删除重复项

Anaconda 中的依赖项和包冲突?

使用 Python3 与 HDFS 交互的最佳模块是什么?

如何在 jupyter notebook 5 中逐行分析 python 3.5 代码

为什么 string.maketrans 在 Python 3.1 中不起作用?

计数大于Pandas groupby 中的值的项目

Python 3 - Zip 是 pandas 数据框中的迭代器

在 linux mint 上安装 python3-venv 模块

python 3中最快的标准输入/输出IO?