无法单击“搜索”按钮
Unable to click the Search button
我无法单击以下 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>
代码
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'));
我无法单击以下 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>
代码
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'));