1

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', 'hello@world.com');

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.

Simon
  • 81
  • 1
  • 12

1 Answers1

3

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

NithyaViji
  • 121
  • 6
  • Thanks. Once again it was a wait problem. – Simon Jun 27 '17 at 07:32
  • Can you tell me a working CSS selector for that email field? As xpath one, I use: I.fillField('//input[@name="email"]','hello@world.com'); and it is working, but I can't get the heck of the CSS selectors. For example: document.querySelector('input[type="email"]') returns the needed element, but I am baffled that any CSS selectors based on that failed. – Simon Jun 27 '17 at 11:49
  • Try executeScript as I.executeScript("document.querySelector(\"input[name='email']\").setAttribute('value', 'hello@world.com');"); – NithyaViji Jun 27 '17 at 12:03
  • The result: invalid element state: Failed to execute 'querySelector' on 'Document': 'input[name='email'‌​]' is not a valid selector. But what I meant and would like to know is: for example in Java I would use something like: driver.findElement(By.cssSelector('input[type="email"]')); where the 'input[type="email"]' is exactly the selector I have checked with the document.querySelector(). So my question is: is there a way to use the string 'input[type="email"]' in a nifty way with Codeceptjs? – Simon Jun 27 '17 at 14:40