I\'m trying to check if an element exists before I can execute this line:
driver.findElement(webdriver.By.id(\'test\'));
This throws an error \"
You want to check whether an element exists before you want to find an element on UI. You can wait until the element gets located on UI then you can perform the find element operation.
Ex: Below code waits until element located then it will perform the find element.
driver.wait(webdriver.until.elementLocated(webdriver.By.id(LocatorValue)),20000)
.then(()=>{
return driver.findElement(webdriver.By.id('test'));
}).then((element)=>{
// Perform any operation what you to do.
return element.click();
}).catch(()=>{
console.log('Element not found');
})