Selenium 无法按类型属性或xpath定位登录框
HTML如下所示Selenium 无法按类型属性或xpath定位登录框,selenium,testing,xpath,automation,Selenium,Testing,Xpath,Automation,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"> 然后
<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">
然后是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应用程序(angular),因此我以后必须寻找另一个无头解决方案。
/*[type='email']
不正确。请尝试以下方法:
//*[@type='email']
请注意,type='email'
谓词表示具有字符串值的子节点'email'
:
<input>
<type>email</type>
</input>
电子邮件
虽然
@type='email'
表示属性type
带有值“email”
/*[type='email']
是不正确的XPath。请尝试以下方法:
//*[@type='email']
请注意,type='email'
谓词表示具有字符串值的子节点'email'
:
<input>
<type>email</type>
</input>
电子邮件
虽然
@type='email'
表示属性type
和值“email”
前面的答案是正确的,但是您也可以尝试这个//输入[@type='email']
前面的答案是正确的,但是您也可以尝试这个//输入[@type='email']
您可以使用任何XPath,正如@Andersson和@zsbapa已经提到的那样
还有一些是
//input[@class='text-input text-input-md' and @type='email']
//input[contains(@type,'email')]
您可以使用任何XPath,正如@Andersson和@zsbapa已经提到的那样 还有一些是
//input[@class='text-input text-input-md' and @type='email']
//input[contains(@type,'email')]
通用语法类似于下面提到的xpath
//tagName[@attribute='value']
通用语法类似于下面提到的xpath
//tagName[@attribute='value']
因为您使用的是WATIR,所以不必编写xpath,只需编写下面的代码即可
b.text_field(type: "email").set "abc@gmail.com"
因为您使用的是WATIR,所以不必编写xpath,只需编写下面的代码即可
b.text_field(type: "email").set "abc@gmail.com"
我很确定只有
input
HTML节点可以有type=“email”
属性,所以在这种情况下指定标记名实际上并没有什么改进。我很确定只有input
HTML节点可以有type=“email”
属性,因此,在这种情况下指定标记名并没有任何改进,实际上您是否实际使用了Watir?考虑到findElement
等方法,这似乎很不寻常。您实际使用的是Watir吗?考虑到findElement
等方法,这似乎不寻常。