1

I'm using the facebook webdriver with PHP Unit

Due to some filtering issues in a table I want to be able to sendKeys but key by key. Let's say I click on the field and I want to enter ' Selenium '

$this->webDriver->findElement(WebDriverBy::id('Sessies'))->click();
$this->webDriver->getKeyboard()->sendKeys('Selenium');

This would just paste ' Selenium ' in the field but I want it to type: S then e then l and so on.

Is there anyway that I can do this besides:

$this->webDriver->getKeyboard()->sendKeys('S');
$this->webDriver->getKeyboard()->sendKeys('e');
$this->webDriver->getKeyboard()->sendKeys('l');
// and so on ... 

EDIT: Trying out andrey's option below:

$var = 'Selenium';
for ($i = 0; $i<strlen($var); $i++)  { 
$character = substr($var, $i,1);
$this->webDriver->getKeyboard()->sendKeys($character);     
} 

Result = it sends the key ' m ' but that's all.

Decypher
  • 690
  • 1
  • 8
  • 30

1 Answers1

1

Only split word on letters and iterate over each of it. I don't know php but thinks this will look like:

//$var it's your word
for ($i = 0; $i<strlen($var); $i++)  { 
    $character = substr($var, $i,1);
    $this->webDriver->getKeyboard()->sendKeys($character);     
} 
Andrey Egorov
  • 1,249
  • 1
  • 12
  • 9
  • It still put it's in all at once. It doesn't make it type letter by letter. – Decypher Aug 28 '14 at 08:37
  • Add waiting time after entering letter – Andrey Egorov Aug 28 '14 at 08:39
  • It's only sending the last letter ' m ' ( Selenium ) that's why it doesn't work/find anything. – Decypher Aug 28 '14 at 08:58
  • $character = substr($var, $i,1); --> should become --> $character = \substr($var, $i,1); and then it works. btw how would I add a greater delay in typing the work? – Decypher Aug 28 '14 at 09:58
  • Actually, `$character = $var[i]` is easier to decipher in this particular case (*i.e.* when only one character is extracted). The backslash probably isn't really required generally, [unless you're doing namespaces (wrong)](http://stackoverflow.com/questions/4790020/what-does-a-backslash-do-in-php-5-3). – You Aug 28 '14 at 10:05