When I run this code
`
const { Builder, By } = require('selenium-webdriver')
const chrome = require("selenium-webdriver/chrome")
let chromeOptions = new chrome.Options();
chromeOptions.addArguments('disable-gpu')
chromeOptions.addArguments('headless')
class Selenium {
constructor (url, elem) {
this.url = url,
this.elem = elem
}
// finds a specfic attribute within an HTML element
async findAttr(attr) {
let driver = new Builder().forBrowser("chrome").setChromeOptions(chromeOptions).build();
try {
await driver.get(this.url);
const _elem = await driver.findElement(By.tagName(this.elem));
return _elem.getAttribute(attr);
} finally {
driver.close();
}
}
}
module.exports = Selenium
`
This error is given UnhandledPromiseRejectionWarning: NoSuchSessionError: invalid session id, I don't know why this is happening or how to fix it... I'm hoping somebody here knows a working solution.
nvm I figured out why its doing it, the browser window is simply closing too quickly.
Temp solution till it gets fixed
setTimeout(function () {driver.quit()}, 100)
nvm I figured out why its doing it, the browser window is simply closing too quickly.
Temp solution till it gets fixed
setTimeout(function () {driver.quit()}, 100)
worked for me
Most helpful comment
nvm I figured out why its doing it, the browser window is simply closing too quickly.
Temp solution till it gets fixed
setTimeout(function () {driver.quit()}, 100)