selenium: ManagedPromise::32 {[[PromiseStatus]]: “pending”} message shown before navigating to the page

后端 未结 1 480
北荒
北荒 2021-01-07 08:20

I tried the following selenium-webdriverJS code:

var webdriver = require(\'selenium-webdriver\');
var browser = new webdriver.Builder().usingServer().withCap         


        
1条回答
  •  清酒与你
    2021-01-07 09:15

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

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

    without having to chain them like this:

    driver.findElement(By.css('#searchBar')).clear().then(function() {
      driver.findElement(By.css('#searchBar')).sendKeys('hello').then(function(){
        driver.findElement(By.css('#searchButton')).click();
      });
    })
    

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

    0 讨论(0)
提交回复
热议问题