selenium:导航到页面之前显示的ManagedPromise :: 32 {[[PromiseStatus]]:“pending”“消息 [英] selenium: ManagedPromise::32 {[[PromiseStatus]]: "pending"} message shown before navigating to the page

查看:491
本文介绍了selenium:导航到页面之前显示的ManagedPromise :: 32 {[[PromiseStatus]]:“pending”“消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了以下selenium-webdriverJS代码:

I tried the following selenium-webdriverJS code:

var webdriver = require('selenium-webdriver');
var browser = new webdriver.Builder().usingServer().withCapabilities({'browserName': 'chrome' }).build();


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");
console.log("attributes: " + ids); //expecting to run after above lines.
browser.quit();

预期:
导航到指定的网址,找到元素,然后打印属性 id ,如下所示:

attributes: show-coordinates

实际:
导航到URL本身之前,打印属性:,并显示以下消息:

Actual: Before navigating to the URL itself, prints attributes: with following message:

attributes: ManagedPromise::32 {[[PromiseStatus]]: "pending"}

环境:

Windows 7 - 64 bit
selenium-webdriver (installed using `npm install selenium-webdriver`)
ChromeDriver
Chrome


推荐答案

您需要从要返回的承诺中提取值使用 then();

You need to extract the value from the promise being returned using then();

所有webdriver命令都会将promise作为promise Manager的一部分返回。这使您可以编写

All webdriver commands return a promise as part of the promise manager. This enables you to write

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回调来提取该值。所以你的代码变成:

But getAttribute(), like many of the Webdriver JS commands, returns a value. In this case you DO need to register a promise callback to extract that value. So your code becomes:

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();

这篇关于selenium:导航到页面之前显示的ManagedPromise :: 32 {[[PromiseStatus]]:“pending”“消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆