Selenium:如何输入空格作为文本字段的值?

标签 selenium phpunit selenium-rc

我有一个正在填充默认值的表单文本字段。我想清除该值并输入空格以断言发生了预期的验证。我正在使用 Selenium RC 和 PHPUnit Selenium 扩展。我怎样才能实现这个目标?

注意:我已经尝试过这样做,但它们不起作用:

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

他们清除字段中的值,但不会在字段中输入空白。

更新:我发现 if you are using Selenium IDE, you can type white space by using their ${space} variable但这在使用 Selenium RC 和 PHPUnit Selenium 扩展时不起作用。

最佳答案

最近我遇到了和 Andrew 一样的问题,${space} 在 Selenium RC 中不起作用。我发现 Zugwalt 的解决方案很有用。这是我捕获空白的方法。

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

希望这有帮助;)

谢谢@!

关于Selenium:如何输入空格作为文本字段的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2914448/

相关文章:

selenium - 当预期消息多于一行时, Protractor ExpectedConditions.textToBePresentInElement 返回 false

symfony - "You cannot define a mapping item when in a sequence"在 symfony 中运行 phpunit 时

error-handling - PHPunit不会显示语法错误-如何修复

selenium-rc - 如何让selenium在点击按钮后等待几秒钟

firefox - Selenium RC 测试 (PHPUnit)

javascript - Selenium RC 中的 selectCancelOnNextConfirmation 替代方案

python - 使用 python 和 selenium 连接到 phantomJs webdriver 时遇到问题

python - 如何避免每次使用 Selenium 和 Python 时都出现 Instagram 登录页面

selenium - 选择与特定文本在同一行中的元素

php - 为什么需要 CIUnit 才能将 PHPUnit 与 CodeIgniter 一起使用?