Monday, 5 June 2017

How to assert element is not present/visible on page

Using Selenium, what is the best way (most reliable) to assert that an element is not present on the page?

We give the element an id:

<div id="12345"></div>

in our Selenium code, we have something like this:

      let el = await driver.findElement(By.id(`12345`));
      await driver.wait(until.elementIsVisible(el), 6000).then(function () {
          // we would fail the test here
          throw new Error('element was not supposed to be found!')
      });

should we simply expect a timeout when searching for the element? Or is there a better way than expecting a timeout?



via Alexander Mills

No comments:

Post a Comment