我与水豚有一些非常奇怪的行为。它固执地拒绝填写我的登录表单的字段。
<fieldset>
<div class="clearfix">
<label for="user_email">E-Mail Adresse</label>
<div class="input">
<input id="user_email" name="user[email]" size="30" type="email" value="">
</div>
</div>
<div class="clearfix">
<label for="user_password">Passwort</label>
<div class="input">
<input id="user_password" name="user[password]" size="30" type="password" value="">
</div>
</div>
<div class="clearfix">
<div class="input">
<input name="user[remember_me]" type="hidden" value="0">
<input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1">
<label for="user_remember_me">angemeldet bleiben</label>
</div>
</div>
</fieldset>
这是乐趣的开始:
within("#login_form"){ find("#user_email")}
=> #<Capybara::Element tag="input" path="/html/body/div[2]/div[@id='content']/div/div[1]/form[@id='login_form']/fieldset/div[1]/div/input[@id='user_email']">
within("#login_form"){ fill_in("#user_email", with: "[email protected]")}
Capybara::ElementNotFound: Unable to find field "#user_email"
我不太了解如何找到但尚未找到元素。另一双对此表示赞赏。
find
和fill_in
的定位符不同:
您可以执行fill_in
。查看答案within("#login_form"){ fill_in("user_email", with: "[email protected]")}
如果是自动完成字段,则可以使用此: