then();
所有的webdriver命令都将诺言作为诺言管理器的一部分返回。这使您能够编写
driver.findElement(By.css('#searchBar')).clear();driver.findElement(By.css('#searchBar')).sendKeys('hello');driver.findElement(By.css('#searchButton')).click();
不必像这样将它们链接起来:
driver.findElement(By.css('#searchBar')).clear().then(function() { driver.findElement(By.css('#searchBar')).sendKeys('hello').then(function(){ driver.findElement(By.css('#searchButton')).click(); });})
但是
getAttribute(),和许多Webdriver
JS命令一样,它返回一个值。在这种情况下,您需要注册一个promise回调以提取该值。因此,您的代码变为:
browser.get('http://localhost:1091/WebTours/sample.html');var btn = browser.findElement(webdriver.By.id('show-coordinates'));browser.sleep(3000);var ids = btn.getAttribute("id").then(function(promiseResult){ console.log("attribute is: " + promiseResult);});browser.quit();
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)