在nodejs中,我想单击element,直到其他元素中的文本不等于'100‘
我试着写这样的代码:
while (this.getLinkText() != '100') {
this.clickOnButton();
}我不知道如何使用js selenium-webdriver做到这一点,因为当我尝试以这种方式获取元素的文本时
driver.findElement(By.xpath(this.path)).getText();它返回'promise‘,而不是一个字符串,所以我不知道如何在while循环中使用它
发布于 2016-11-15 17:14:40
虽然循环是一条无处可走的道路,但请尝试使用带有回调的递归函数。我遇到了类似的问题,需要在日历中选择年份(单击“下一步”,直到我得到正确的年份)
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!');
});https://stackoverflow.com/questions/38038494
复制相似问题