如何解决无法点击搜索按钮
我无法单击以下HTML中的“搜索”按钮。我尝试使用.css,.cssContaining,.className,.xpath找到它。任何帮助将不胜感激!
<div class="ncol-xs-offset-11 ncol-md-3 saveFilter">
<button class="searchBtn-align">
<i class="fa fa-search fa-lg">
</i> Search
</button>
<button class="searchBtn-align">
<i class="fa fa-refresh fa-lg">
</i> Reset
</button>
</div>
CODE
var buttonSearch = element(by.xpath('//button[. = " Search"]'))
browser.isElementPresent(buttonSearch).then(function (present) {
if (present == true) {
//buttonSearch.click();
console.log('Search button was clicked');
}
else {
console.log('Search button was NOT located');
}
})
解决方法
您可以按以下方式使用xpath定位器://button[contains(.,'Search')]
。然后
var buttonSearch = element(by.xpath("//button[contains(.,'Search')]"))
buttonSearch.isPresent().then(function (present) {
if (present) {
buttonSearch.click().then(()=>{
console.log('Search button was clicked');
});
} else {
console.log('Search button was NOT located');
}
})
或使用async
var buttonSearch = element(by.xpath("//button[contains(.,'Search')]"))
if (await buttonSearch.isPresent()) {
await buttonSearch.click();
console.log('Search button was clicked');
} else {
console.log('Search button was NOT located');
}
,
您尝试过使用element(by.css('.searchBtn-align'));
吗?
甚至是element(by.buttonText('Search'));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。