views:

365

answers:

5

I have a form text field that is being populated with a default value. I would like to clear the value and enter white space to assert that the expected validation occurs. I am using Selenium RC and the PHPUnit Selenium extension. How can I achieve this?

Note: I have already tried doing these, but they do not work:

$this->type('FirstName', "  "); //spaces
$this->type('FirstName', "\t"); //tab character

They clear the value from the field, but they do not enter the white space into the field.

Update: I found that if you are using Selenium IDE, you can type white space by using their ${space} variable but this does not work when using Selenium RC and the PHPUnit Selenium extension.

A: 

How about setting it's value to an empty string ('')?

Eimantas
What would be the syntax to set an element's value?
Andrew
A: 

How about using the keyPress() function to "press" the spacebar?

Ross Patterson
+1  A: 

You could use javascript injection and manipulate the value directly

selenium.getEval("this.browserbot.findElement('FirstName').value = ' ';");

Note this will not fire off any events so you would have to manually trigger them if desired.

Zugwalt
+1  A: 

Hi all, recently I am having the same problem just like Andrew where the ${space} isn't work in Selenium RC. I found out that Zugwalt's solution is useful. Here is what I did to capture the whitespace.

selenium.focus("txt_textbox1");
selenium.keyPressNative("32");
strOutput = selenium.getEval("this.browserbot.findElement('txt_textbox1').value = ' ';");

Hope this help ;)

THanks @!

huahsin68
A: 

You can try selenium.typeKeys('FirstName'," "); Please let me know if it worked.

vamyip