sunling90
sunling90

Reputation: 31

selenium-webdriver: how to use driver.quit() in javascript

How can I terminate driver instance without throwing an exception? Sometimes it quits before anything is done.

driver.get('http://www.google.com');
var query = driver.wait(until.elementLocated(By.name("q")));
query.sendKeys('webdriver\n');
driver.wait(until.titleIs('webdriver - Google Search')); 
driver.quit();

Upvotes: 0

Views: 1901

Answers (2)

andreino7
andreino7

Reputation: 11

Those methods return promises. So you need to wait for them to execute those operations in order. For example

await driver.get('http://www.google.com');

See https://github.com/SeleniumHQ/selenium/tree/master/javascript/node/selenium-webdriver#usage for more details

Upvotes: 1

Vin
Vin

Reputation: 177

you can also try the following function and call that function in your script

public void tearDown()
{
 if(driver!=null)
 {
  driver.quit();
 }
}`

Upvotes: 0

Related Questions