Angularjs 输入字段中的这段代码使用哪个定位器
我有一个问题,还有一个输入字段,我不知道如何使用定位器。在代码中它是Angularjs 输入字段中的这段代码使用哪个定位器,angularjs,selenium-webdriver,protractor,Angularjs,Selenium Webdriver,Protractor,我有一个问题,还有一个输入字段,我不知道如何使用定位器。在代码中它是 '<input _ngcontent-tvt-19="" class="form-control ng-pristine ng-valid ng-touched" placeholder="You can search keywords" type="text"> 但它不起作用。我也尝试过cssContainingText,但它不起作用。你对定位器有什么想法,或者我如何更改代码行 最简单的解决方案是在输入字段中添
'<input _ngcontent-tvt-19="" class="form-control ng-pristine ng-valid ng-touched" placeholder="You can search keywords" type="text">
但它不起作用。我也尝试过cssContainingText,但它不起作用。你对定位器有什么想法,或者我如何更改代码行 最简单的解决方案是在输入字段中添加ID或类,然后使用:
element(by.Id(<id>))
元素(by.Id())
或:
元素(by.css())
以下是几个示例:
$('input[placeholder="You can search keywords"]')
$('input[_ngcontent-tvt-19]')
您可以使用xpath,如下所示
元素(by.xpath(“//input[@placeholder='youcan search keywords']”) 您还可以发布此元素的父元素吗?(理想情况下HTML越多越好)可能有更好的方法。您有权更改元素吗?如果是这样的话,像其他人说的那样添加ID是一个可靠的选择。若并没有,仍然有办法做到。上面代码中的定位器是什么,我猜它不完整。它是完整的。两个定位器都将返回您的输入字段。签出快捷方式定位器很高兴听到,很好:)
element(by.css(<class_name>))
$('input[placeholder="You can search keywords"]')
$('input[_ngcontent-tvt-19]')