【发布时间】:2020-12-06 10:50:50
【问题描述】:
我不是一个非常有经验的编码员,如果我说愚蠢的话,我深表歉意。
我正在使用 Python(在 Spyder 中)让 Selenium 填写包含用户名和密码的网站表单。这是目标 - link。
当我在常规浏览器中按 F12 查找“用户名”元素时,我得到以下信息:
<input class="slds-input input" type="text" aria-describedby="" placeholder="Username" id="172:0" data-aura-rendered-by="176:0" data-interactive-lib-uid="2">
所以我尝试使用 ID 定位元素。但是,当我运行脚本时,我在 Chrome 中收到以下错误:
NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"[id="172:0"]"}
当我在 Firefox 中运行它时也是这样:
NoSuchElementException: Unable to locate element: [id="172:0"]
当我在 Selenium 驱动的浏览器中查看 HTML 时,我可以看到页面代码(即元素 ID)不同,如下所示
<input class="slds-input input" type="text" aria-describedby="" placeholder="Username" id="78:2;a" data-aura-rendered-by="82:2;a" data-interactive-lib-uid="2">
我最好的猜测是 HTML 代码的差异是错误的原因。我发现人们发布了类似的问题,但略有不同,我无法使用那里提出的解决方案来解决我的问题。如果有人可以帮助我处理我的案子,我将不胜感激。
【问题讨论】:
-
对链接的访问是私有的吗?如果可能,请将其添加到问题中,以便可以重现,以便更容易为您提供帮助。
-
@Fake,谢谢 - 添加了链接!
-
@Nam 参考更新后的答案