2

I'm using Node.js selenium-webdriver and I have this annoying issue. The issue is that the wait function throws an exception in console.

var webdriver = require('selenium-webdriver'),
By = webdriver.By,
until=webdriver.until;

var driver = new webdriver.Builder().forBrowser('chrome').build();

driver.get('https://****');

driver.manage().timeouts().implicitlyWait(5000);

driver.findElement(By.xpath("//div[@class='email-wrapper']/input")).sendKeys("user@mail.com").then(function(element){
    console.log("success "+ element);
});

driver.findElement(By.xpath("//div[@class='password-wrapper']/input")).sendKeys("123456").then(function(element){
    console.log("success "+ element);
});

driver.findElement(By.xpath("//div[@class='button']/button")).getText().then(function(text){
    console.log("Button text "+ text);
});

driver.findElement(By.xpath("//div[@class='button']/button")).click().then(function(element){
    console.log("Button found "+ element);
});

driver.sleep(10000);
driver.quit();

Exception:

C:\\webdrivertut\library.js:13
        driver.manage().timeouts().implicitWait(5000);
                        ^

TypeError: driver.manage(...).timeouts is not a function
    at Object.<anonymous> (C:\\webdrivertut\library.js:13:18)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
2

"chromedriver": "^2.36.0", "selenium-webdriver": "^4.0.0-alpha.1",

here example of create driver function:

import webdriver from 'selenium-webdriver'
import chrome from 'selenium-webdriver/chrome'
import chromedriver from 'chromedriver'
const TIMEOUT = 300000000

export default async () => {
 chrome.setDefaultService( new chrome.ServiceBuilder( 
chromedriver.path ).build() )

 const chromeCapabilities = webdriver.Capabilities.chrome()

 const chromeOptions = { 'args': [ 'user-data-dir=/Users/user/selenium/bp/' ] }
chromeCapabilities.set( 'chromeOptions', chromeOptions )

 const driver = new webdriver.Builder()
.withCapabilities( chromeCapabilities )
.build()

 await driver.manage().setTimeouts( { implicit: TIMEOUT, pageLoad: 
TIMEOUT, script: TIMEOUT } )
console.info( await driver.manage().getTimeouts() )

 return driver
}

documentation: http://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html

2

I had a same issue. It is due to a version issue. You can use:

driver.manage().setTimeouts() or driver.sleep()

please, check the documentation for more details.

1

I was having the same problem and this fixed it:

const capabilities = await driver.getCapabilities();
capabilities['map_'].set('timeouts', { implicit: TIMEOUT, pageLoad: TIMEOUT, script: TIMEOUT }); 

getCapabilities() retrieves the Map of the driver's capabilities which you can then interact with using the default methods outlined in the MDN Javascript reference.

You can check that the capabilities are the ones you set by then logging them to the console

console.log(await driver.getCapabilities());

(edit: linked to the Selenium documentation)

  • +1 This probably works, but is a little bit more verbose than manage().setTimouts() :) – Niels van Reijmersdal Aug 16 '18 at 11:49
0

Maybe you need more information into implicity

driver.manage().timeouts().implicitlyWait(5000);

like

driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);

  • 1
    Downvoted, because timeouts() is replaced by setTimeouts() in the version the original poster is using. – Niels van Reijmersdal Aug 16 '18 at 11:31
0
driver.manage().timeouts().implicitWait(5000);

should be

driver.manage().timeouts().implicitlyWait(5000);

or

driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);

The error shows you using implicitWait but the source code currently shows implicitlyWait (with"ly") so this is confusing unless it is being changed dynamically at runtime not by you.

  • Downvoted, because timeouts() is replaced by setTimeouts() in the version the original poster is using. – Niels van Reijmersdal Aug 16 '18 at 11:31
0

Since version v4.0.0-alpha.1 the timeouts() has been changed into setTimeouts().

API Changes: Changes to lib/webdriver.Options (driver.manage()):

  • Removed timeouts (use get/setTimeouts)

Read more in the changelog

Your code should look something like this:

driver.manage().setTimeouts( { implicit: 5000 } )

See the API documentation for others timeout parameters (e.g. pageLoad and script).

0

It works and then stops the execution of subsequent code. So I tried using Promises:

this.driverWait = async function (explicitWaitMS) {
    // create a new promise inside of the async function
    let promise = new Promise((resolve, reject) => {
        setTimeout(() => resolve(true), explicitWaitMS) // resolve
    });

    // wait for the promise to resolve
    await promise;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.