Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Codeception function to seeOrWaitForElement

I've got an application which I want to test with selenium/codeception. It has a lot of ajax function which changes the pages (show/hide sections of the page) which codeception at the moment doesn't handle well.

The problem I am having is I want to click on buttons/elements which either

  • are already on the page (ajax calls finished early)
  • which are not yet on the page (waiting for ajax response)

If I use waitForElement() it only seems to works in the second case (it waits for the element to appear and continues) but if the element is already present waitForElement will timeout and fire an Fail.

What I am looking for is a seeOrWaitForElement() function but I can't figure out how to insert logic in codeception.

Is this function available somewhere or how can I solve this problem in another way?

like image 590
Richard Deurwaarder Avatar asked Oct 25 '25 05:10

Richard Deurwaarder


1 Answers

You could use

waitForJs("return document.querySelector('".$element."') != null", $seconds);

which will wait until the element exists (and returns instantly if the element already is present).

like image 174
Reiscracker Avatar answered Oct 28 '25 02:10

Reiscracker