-1

Problem is that my codeception test is actually passing and button is clicked, but for some reason it stops going further with error in title.

$I->click('onsomefield');

$I->fillField(['name' => 'password'], 'password');

$I->waitForJS("let buttons=document.querySelectorAll('button');buttons.forEach(function(button){button.style.disabled=false});return buttons[1].click()",10);

I expect my test to be passed but i get an error as in title

Full error text is:

[Facebook\WebDriver\Exception\UnexpectedJavascriptException] javascript error: Cannot read property 'click' of undefined (Session info: chrome=75.0.3770.142) (Driver info: chromedriver=75.0.3770.140 (2d9f97485c7b07dc18a74666574f19176731995c-refs/branch-heads/3770@{#1155}),platform=Windows NT 10.0.18362 x86_64)

Artur O
  • 174
  • 1
  • 12
  • This is an error of your javascript code. Try clicking the first button with `return buttons[0].click()`; or click in forEach loop. – Naktibalda Aug 04 '19 at 11:55
  • actually there are 2 buttons and i need the last one, so that's why im poiting on [1]. any way i have found a solution – Artur O Aug 04 '19 at 18:09

1 Answers1

1

I solved my issue with.

in my case front end was on react i guess, and button did not have an id, i have tried so many option and i tried executingJS waiting to executejs, actually it worked but i was still throwing an error that is in title of this question, found here that there is a special class

Codeception\Util\Locator

and it can be used it with click, so setting my locator to

    use Codeception\Util\Locator;
   $I->click('login' , Locator::lastElement('#login-methods-body-user_credentials'));

worked, i hope you can select an option that works for you there.

Artur O
  • 174
  • 1
  • 12