Alexandre Bourlier Alexandre Bourlier - 2 years ago 139
Javascript Question

Selenium - Click on a button until some element appears

I am trying to click on the

Check for new emails
button of the Yopmail's website until an email is received (because at the beginning the inbox is empty).

I am using the
implementation of
, running my tests with
. Here is how I am trying to click until the element appears :

driver.wait(until.elementLocated(By.css('#f .sbut')));
driver.findElement(By.css('#f .sbut')).sendKeys(Key.ENTER);
driver.wait(until.elementLocated('ifinbox')));// Switching iframe

bool = driver.isElementPresent("m1");

while (!bool) {
driver.sleep(500);// 500ms
bool = driver.isElementPresent("m1");

The ligne
bool = driver.isElementPresent("m1");
fails with the following unexplicite error message :

Error: the error {} was thrown, throw an Error :)
at Array.forEach (native)

I guess I can't build a while loop on a promise... maybe... But then I dont really understand why it fails, and how to write this while loop properly.

Any suggestion is most welcome!

Answer Source

According to the source code, isElementPresent() accepts a locator or an element, but you are passing in a string m1. Assuming this is an id:

bool = driver.isElementPresent("m1"));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download