2015-10-02 81 views
0

这是很容易使用rack_test司机与水豚,以获得选定的单选按钮选择得单选按钮。水豚:使用webkit的或吵闹鬼

# with rack_test 
page.set('input_id') 
# => "checked" 
page.find('[checked]') 
# => #<Capybara::Node::Element tag="input" path="/html/body/p[1]/label[1]/input"> 

但是,这不适用于webkit或poltergeist。

# with webkit or poltergeist 
page.set('input_id') 
# => "" 
page.find('[checked]') 
Capybara::ElementNotFound: Unable to find css "[checked]" 

我使用#selected?方法也试过,但它似乎并不奏效单选按钮。

# with any driver 
page.set('input_id') 
page.all('input').select(&:selected?) 
# => [] 

如何在webkit或poltergeist中使用水豚检查单选按钮?

回答

2

您正在运行JS支持浏览器中的属性和属性之间的区别。你在机架测试中所做的工作,因为它只知道属性。为了找到在其他浏览器中选中的输入,你可以做

find('input:checked') 

,或者你可以做这样的事情

find(:checkbox, 'input_id', checked: true) 
find(:radio_button, 'input_id', checked: true) 
find(:field, 'input_id', type: 'checkbox', checked: true) 

等等

+0

这是它。谢谢! – steel