6

I am not familiar with codeception. I am trying to insert a text in an input field and press the ENTER button.

$I->fillField('#token-input-yw1', 'Some string');
$I->pressKey('#token-input-yw1', 13);

The text is entered but the enter key is not pressed. Any ideas?

buerma
  • 73
  • 1
  • 1
  • 5

3 Answers3

14

If anyone still have problem with pressing Enter key, here is a solution: (if you are using Webdriver with Selenium)

$I->pressKey('#input',WebDriverKeys::ENTER);
pwl
  • 156
  • 1
  • 3
2

Hopefully someone will find this useful.

See http://codeception.com/docs/modules/WebDriver#pressKey

pressKey

Presses the given key on the given element. To specify a character and modifier (e.g. ctrl, alt, shift, meta), pass an array for $char with the modifier as the first element and the character as the second. For special keys use key constants from WebDriverKeys class.

<?php
// <input id="page" value="old" />
$I->pressKey('#page','a'); // => olda
$I->pressKey('#page',array('ctrl','a'),'new'); //=> new
$I->pressKey('#page',array('shift','111'),'1','x'); //=> old!!!1x
$I->pressKey('descendant-or-self::*[ * `id='page']','u');`  //=> oldu
$I->pressKey('#name', array('ctrl', 'a'), \Facebook\WebDriver\WebDriverKeys::DELETE); //=>''
?>

param $element

param $char Can be char or array with modifier. You can provide several chars.

throws \Codeception\Exception\ElementNotFound

Please note, that you may need to add \ or \Facebook\WebDriver\ before WebDriverKeys:

\Facebook\WebDriver\WebDriverKeys::ENTER

  • 1
    Using it in helper, I need to add `\ ` as for `\WebDriverKeys::ENTER`. Else it will throw an error `Fatal error: Class 'Codeception\Module\WebDriverKeys' not found` – FaizFizy Jul 28 '16 at 01:29
1

I had the same problem. I pressed enter this way:

$I->executeJS('event.keyCode=13');
$I->fillField('input onkeypress=','13');
$I->pressKey('photo_link', '13');

But it didn't work.

I fixed it with the next code:

$I->executeJS("$('input#photo_link').trigger(jQuery.Event('keypress', {keyCode: 13}));");

It equals enter key, try it.

FelAl
  • 31
  • 2