Search code examples
webdrivercodeceptionacceptance

Codeception WebDriver acceptance test can't click on an element it can see


I've looked at the other answers to this question, but none applies. Mine is a very bizarre version of the problem.

The test code is in a loop that performs the same operations on four tabs (not browser tabs). The process is:

Click on one of four tabs. Click on a button to populate a grid. Perform 5 operations on the grid. (repeat for each tab)

All five operations work fine the first time through the loop. The second time through the loop, the third operation fails:

$I->clickWithRightButton("//div[text() = '" . oPageVariables::$namePrefix . 
    $name . "']");
$I->waitForElement("//span[text() = 'Change Category']");
$I->see('Change Category');
$I->wait(1);
$I->click("//span[text() = 'Change Category']");

Here's the relevant HTML:

<span class="x-menu-item-text" id="ext-gen315">Change Category</span>

I can't use the ID because it can change. Note that the element I want to click on is the same on each tab.

The right-click works to drop down the menu, but the click action fails with "element is not visible," even though "$I->waitForElement" and I->See work fine.

Watching the screen, the "Change Category" element is definitely visible.

Here's the weird part. No matter how I change the order in which the tabs are tested, it always fails on the second tab tested (the second time through the loop). That means both the selectors and the code are correct. I've tried adding the class to the selector, but the result is the same.

Any clues appreciated.


Solution

  • Based on Naktibalda's suggestion, I thought I had solved the original question by making the text in each drop-down option unique for each tab.

    Unfortunately, CodeCeption could no longer click on the tab heading to change tabs for the second pass. This works once at that beginning (I can click on any tab heading before running the first pass). In subsequent passes, The headings of the non-active tabs (which are unique) were not considered visible, though I could see them fine.

    The only thing that finally worked was to add this at the end of the loop:

    $I->reloadPage();
    

    I consider this a bug, but I'm not sure if it's a bug in CodeCeption, WebDriver, or ExtJS 3.