Search code examples
syntaxcodeceptjs

Codeceptjs selectors: How to select the "email" input field?


I really need help with the syntax.

I have the input field:

<input class="email__field ng-pristine ng-empty ng-valid-email ng-invalid ng-invalid-required ng-touched" name="email" ng-model="authForm.email" ng-keypress="keypress($event);" ng-disabled="false" focused="true" required="" style="" type="email">

According the documentation: http://devdocs.io/codeceptjs/helpers/seleniumwebdriver/index#fillfield

I.fillField('email', '[email protected]');

should locate the element by name. But the test fails with the error message: "Field email not found by name|text|CSS|XPath"

Is the syntax wrong or maybe something is wrong with the webdriver? E.g. The previous command/step is:

I.amOnPage(some url here); 

and it is working, so I think the webdriver should be ok.


Solution

  • The Syntax you used was correct. Locating the element may have some problem.

    Try to debug the issue by the following,

    1) Add a wait --> I.wait(2) seconds between "I.amOnPage" and "I.fillField"
    2) Try to click the element 'email' and then fillField I.click('//input[@name='email']');I.fillField('email');
    3) Try to pass a xpath for fillField, may be there was another element which is disabled. eg: I.fillField('//input[@ng-model="authForm.email"][@name='email']')

    And also please make sure the element was not inside a iframe, if it is means you need to switch to the frame first and then do actions