In Selenium 2 I want to ensure that an element on the page that the driver has loaded does not exist. I\'m including my naive implementation here.
WebEle
If you're using the Javascript API, you can use WebElement.findElements()
. This method will return a Promise with an array of found elements. You can check the length of the array to ensure no items were found.
driver.findElements(By.css('.selector')).then(function(elements) {
expect(elements.length).to.equal(0)
})
I'm using Chai assertion library inside the Promise's callback to expect a certain value.
Reference: https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/index_exports_WebElement.html