1

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 NodeJS implementation of Selenium, running my tests with Mocha. Here is how I am trying to click until the element appears :

driver.get('http://yopmail.com');
driver.wait(until.elementLocated(By.css('#f .sbut')));
driver.findElement(By.name('login')).sendKeys(name);
driver.findElement(By.css('#f .sbut')).sendKeys(Key.ENTER);
driver.wait(until.elementLocated(By.id('ifinbox')));// Switching iframe
driver.switchTo().frame("ifinbox");


bool = driver.isElementPresent("m1");


while (!bool) {
  driver.switchTo().defaultContent();
  driver.findElement(By.id("lrefr")).click();
  driver.sleep(500);// 500ms
  driver.switchTo().frame("ifinbox");
  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!

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
Alexandre Bourlier
  • 3,972
  • 4
  • 44
  • 76

1 Answers1

2

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(By.id("m1"));
Louis
  • 146,715
  • 28
  • 274
  • 320
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • You are right. Maybe I can't read [this documentation properly then](https://selenium.googlecode.com/git/docs/api/javascript/module_selenium-webdriver_class_WebDriver.html#isElementPresent). I believe it is written there I can pass a string as an argument, which will be tried against the className, id, etc. No? Thank you very much anyway! I have been struggling with this for a couple of hours already – Alexandre Bourlier Sep 10 '15 at 14:06
  • 1
    @AlexandreBourlier I think the docs are a bit confusing here - they probably just trying to specify what type of locators can be used here.. – alecxe Sep 10 '15 at 14:14
  • I think you are right. This is what confused me. Now I'll know. Thanks again – Alexandre Bourlier Sep 10 '15 at 14:21