Selenium Webdriver How To Increase Time Out for Page Load, Script Load or Element Locator

I couldn’t find at Stackoverflow on how to increase the timeout and the Selenium API not that easy to find on how to use it.

For Selenium WebDriver using NodeJS below is how to increase its time outs. The number is in milliseconds.

 let driver = await new Builder().forBrowser('chrome')
                .setChromeOptions(new chrome.Options().headless())
                .setFirefoxOptions(new firefox.Options().headless())
                .build();

 driver.manage().setTimeouts({implicit: 120000, script: 120000, pageLoad:120000});

From Selenium Documentation

The following timeouts are supported (all timeouts are specified in milliseconds):

  • implicit specifies the maximum amount of time to wait for an element locator to succeed when locating elements on the page. Defaults to 0 milliseconds.
  • pageLoad specifies the maximum amount of time to wait for a page to finishing loading. Defaults to 300000 milliseconds.
  • script specifies the maximum amount of time to wait for an evaluated script to run. If set to null, the script timeout will be indefinite. Defaults to 30000 milliseconds.

Reference:
https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/lib/webdriver_exports_Options.html