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 \"
I know this is a bit late, but this is the code that worked for me.
var assert = require('assert');
var expect = require('chai').expect;
var should = require('chai').should();
var chai = require('chai');
var chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
chai.should();
var webdriver = require('selenium-webdriver');
By = webdriver.By;
until = webdriver.until;
describe('checking if an element id exists', function() {
it.only('element id exists', function () {
var driver = new webdriver.Builder().forBrowser('chrome').build();
driver.get('http://localhost:3000');
this.timeout(6000);
return driver.wait(until.elementLocated(By.id('idWeWantToTest')), 5 * 1000).then( (e) => {
}, function(err) {
throw {
msg: "element not found"
}
}).then( () => {
driver.quit();
});
});
})