When I run the script, the automated web browser does load and so does the website I wanted it to load but it shuts off instantly without doing anything else. I had looked at the docs and used the wait method in case the website I was trying to load does a lot of AJAX loading but it still doesn't seem to be working. Can anyone please explain what is going on and how I am getting this error?
Here is the JavaScript code:
const {Builder, By, until} = require('selenium-webdriver');
(async function helloSelenium() {
let driver = await new Builder().forBrowser('safari').build();
await driver.get('https://www.google.com/?client=safari');
let ele = await driver.wait(until.elementLocated(By.id('gbqfbb'), 10000));
let b = await driver.findElement(By.id('gbqfbb'));
console.log(b.getText());
await driver.quit();
})();
And here is the error:
user@MacBook-Pro webscraper % node webscraper.js
Promise { <pending> }
/Users/user/Documents/Web/webscraper/node_modules/selenium-webdriver/lib/error.js:522
let err = new ctor(data.message)
^
NoSuchSessionError
at Object.throwDecodedError (/Users/user/Documents/Web/webscraper/node_modules/selenium-webdriver/lib/error.js:522:15)
at parseHttpResponse (/Users/user/Documents/Web/webscraper/node_modules/selenium-webdriver/lib/http.js:548:13)
at Executor.execute (/Users/user/Documents/Web/webscraper/node_modules/selenium-webdriver/lib/http.js:474:28)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async Driver.execute (/Users/user/Documents/Web/webscraper/node_modules/selenium-webdriver/lib/webdriver.js:735:17) {
remoteStacktrace: ''
}
Try to change the below
From
let ele = await driver.wait(until.elementLocated(By.id('gbqfbb'), 10000));
to
let ele = await driver.wait(until.elementLocated(By.id('gbqfbb')), 10000);
t's also important to notice that if this method throws an exception (timeout exception), so you must try-catch it too.