gpt4 book ai didi

selenium - 无法通过 type 属性或 xpath 定位登录框

转载 作者:行者123 更新时间:2023-11-28 21:01:55 25 4
gpt4 key购买 nike

HTML 如下所示

<input class="text-input text-input-md" dir="auto" ng-reflect-klass="text-input" ng-reflect-ng-class="text-input-md" type="email" aria-labelledby="lbl-14" autocomplete="off" autocorrect="off" placeholder="" ng-reflect-type="email">

代码找不到登录框...通过属性尝试

var email_xpath = "//*[type='email']" 

然后 xpath

var email_xpath = "/html/body/ion-app/ng-component/ion-split-pane/ion-nav/page-login/ion-content/div[2]/ion-list/ion-item[1]/div[1]/div/ion-input/input"
var email = webDriver.findElement(By.xpath(email_xpath))

但是还是获取不到元素....

===============已更新===============

下面发布的大多数解决方案都适用于 selenium firefox 驱动程序。问题确实出在我在 scala 中使用的 htmlunit 驱动程序上。可能它无法正确处理 javascript。我用 firefox 驱动程序更改了它,您的解决方案运行良好。正在测试的应用程序是一个 Ionic 应用程序(角度),因此我稍后将不得不寻找另一个 headless 解决方案。

最佳答案

//*[type='email'] 不是正确的 XPath。试试下面的方法:

//*[@type='email']

请注意,type='email' 谓词表示具有字符串值 'email' 的子节点:

<input>
<type>email</type>
</input>

虽然 @type='email' 表示 属性 type 的值为 "email"

关于selenium - 无法通过 type 属性或 xpath 定位登录框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52289836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com