Capybara RackTest无法点击或找到按钮,但Selenium可以

时间:2012-11-27 22:10:19

标签: capybara selenium-webdriver rack-test

我在使用Capybara(2.0.0)进行Cucumber测试时遇到了麻烦。

这是在RackTest中运行时由page.html生成的(有效)html:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <title>EmbeddedUiWeb</title>
</head>
<body class="embedded_ui">

<form action="/patient_context/test_host" id="patientidentity" method="POST">
  <input id="root" name="root" type="text" value="root"/>
  <input id="extension" name="extension" type="text" value="extension"/>
  <input class="btn" type="Submit" value="Show Stuff"/>
</form>


</body></html>

Capybara方法click_on("Show Stuff")返回错误:

  Unable to find link or button "Show Stuff" (Capybara::ElementNotFound)
  org/jruby/RubyBasicObject.java:1704:in `__send__'
  org/jruby/RubyKernel.java:2101:in `send'
  org/jruby/RubyBasicObject.java:1704:in `__send__'
  org/jruby/RubyKernel.java:2101:in `send'

使用Selenium驱动程序时效果很好,有趣的是page.html生成了不同的源

<HTML><HEAD><META content="IE=8.0000" http-equiv="X-UA-Compatible">
<TITLE>EmbeddedUiWeb</TITLE></HEAD>
<BODY class=embedded_ui>
<FORM id=patientidentity method=post action=/patient_context/test_host>
<INPUT id=root value=root type=text name=root></INPUT> 
<INPUT id=extension value=extension type=text name=extension></INPUT> 
<INPUT class=btn value="Show Stuff" type=submit></INPUT> 
</FORM>
</BODY></HTML>

感谢您的帮助!我需要它!

1 个答案:

答案 0 :(得分:1)

属性必须全部小写。设置按钮type=submit解决了问题