0

After adding some input and pressing a button on the targeted page, a JS script will run which will result in (among other things) a text displayed within the page.

The "$I->see" line is the very last part of a longer test which up to that point is successful.

  • triple-checked naming, syntax or spelling errors;
  • tried using both CSS and XPath to the text;
  • tried using Locator (but failed miserably due to not knowing exactly how to set it up with Webdriver);

The error I keep getting in the terminal is:

Element located either by name, CSS or XPath element with was not found.

Webpage paragraph part:

<div class="doc-remote-add" style="background-color: rgb(250, 255, 189); border-color: rgb(247, 218, 56);">
    <b>Important Delivery Info</b>
    <br/>
    The text I am searching for with codeception is here (no, there is no <p>).
</div>

If nothing else, can anyone write a decent Locator configuration plan? The use \Codeception\Util\Locator; from the official page isn't really cutting it.

Rohit
  • 25
  • 6
Valentin
  • 1,371
  • 1
  • 11
  • 15

3 Answers3

0

You can try to reselect element from DOM on exception:

try {
        $I->seeElement($selector);
    } catch (\Facebook\WebDriver\Exception\StaleElementReferenceException $e) {
        $selector = <reselect_element_from_DOM>;
        $I->seeElement($selector);
    }
0

Thanks, Sergey, but I was able to find a much more simple solution.

Indeed, the main problem was that the test was looking for the text immediately. The easiest and most elegant way to solve this is to put an $I->wait(); before the see command, so it comes like this

/* ...
rest of test
... */
$I->wait(3);
$I->see('text i wanna see');
Valentin
  • 1,371
  • 1
  • 11
  • 15
0

You can use this method in this case:

$I->waitForElement($element, $timeout = null);

Method waits until the element appears on the page.