在nodejs中,我想单击元素,直到其他元素中的文本不等于“ 100”
我尝试编写如下代码:
while (this.getLinkText() != '100') {
this.clickOnButton();
}
我不知道如何用js selenium-webdriver做到这一点,因为当我尝试以这种方式获取元素的文本时
driver.findElement(By.xpath(this.path)).getText();
它返回'promise'不是字符串,所以我不知道如何在while循环中使用它
最佳答案
尽管循环是一条通往无处的道路,但请尝试对回调使用递归函数。
我遇到了类似的问题,有必要在日历中选择年份(单击“下一个”,直到获得正确的年份)
var yearToFind = '2016';
function chooseYear(callback) {
// get current year from calendar
driver.findElement(webdriver.By.xpath('.//*[@class="ui-datepicker-year"]'))
.getText()
.then(function(currentYear) {
if (currentYear != yearToFind) {
// click "next year" button and call chooseYear function again
driver.findElement(webdriver.By.xpath('.//a[@class="ui-datepicker-next-year"]'))
.then(function(subelement) {
subelement.click().then(function() {
chooseYear(callback)
});
})
} else {
// do your actions if the year is correct
callback();
}
});
}
chooseYear(function() {
console.log('I have got the correct year finally!');
});
关于javascript - Selenium js单击元素,直到文本不相等,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38038494/