Selenium:如何输入空格作为文本字段的值?
我有一个表单文本字段,其中填充了默认值。我想清除该值并输入空格以断言发生了预期的验证。我正在使用 Selenium RC 和 PHPUnit Selenium 扩展。我怎样才能实现这个目标?
注意:我已经尝试过执行这些操作,但它们不起作用:
$this->type('FirstName', " "); //spaces
$this->type('FirstName', "\t"); //tab character
它们清除字段中的值,但不会在字段中输入空格。
更新:我发现如果您使用Selenium在 IDE 中,您可以使用 ${space}
变量 键入空格,但这在使用 Selenium RC 和 PHPUnit Selenium 扩展时不起作用。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
您可以尝试
selenium.typeKeys('FirstName'," ");
请告诉我是否有效。
You can try
selenium.typeKeys('FirstName'," ");
Please let me know if it worked.
这应该适用于带有 Selenium 的 phpunit:
如果您想输入一个句子,则以下内容将不起作用:
以下内容将:
This should work for phpunit with Selenium:
If you want to enter a sentence, the following won't work:
The following will:
最近我遇到了和 Andrew 一样的问题,${space} 在 Selenium RC 中不起作用。我发现 Zugwalt 的解决方案很有用。这是我为捕捉空白所做的事情。
希望这有帮助;)
谢谢@!
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.
Hope this help ;)
THanks @!
我在 github 上的 phpunit-selenium 代码中修复了这个问题,并向维护者提出了拉取请求。
如果有人关心的话,这是我的要点:
https://github.com/undernewmanagement/phpunit-selenium /提交/1b783ba8cfe4736f525b316a75a991e0a701afd1
I fixed this in the phpunit-selenium code on github and made a pull request to the maintainer.
Here is my gist if anyone cares:
https://github.com/undernewmanagement/phpunit-selenium/commit/1b783ba8cfe4736f525b316a75a991e0a701afd1
您可以使用 javascript 注入并直接操作该值,
请注意,这不会触发任何事件,因此您必须根据需要手动触发它们。
You could use javascript injection and manipulate the value directly
Note this will not fire off any events so you would have to manually trigger them if desired.
将其值设置为空字符串 ('') 怎么样?
How about setting it's value to an empty string ('')?
使用 keyPress() 函数“按下”空格键怎么样?
How about using the keyPress() function to "press" the spacebar?