简体   繁体   English

水豚Poltergeist和硒不同

[英]Capybara Poltergeist and Selenium different

  find(:css, "//input[@id='component_1']").set(true) #poltergeist
  # find(:css, "//label[@for='component_1']").click #selenium

I have an issue alternating between selenium and poltergeist: 我有一个硒和Poltergeist之间交替的问题:

The top find method only works in Poltergeist and I need to comment out the bottom one. 顶部查找方法仅在Poltergeist中有效,我需要注释掉底部的方法。 The bottom method only works in Selenium and not Poltergeist. 底部方法仅适用于Selenium,而不适用于Poltergeist。

I have to set the INPUT to true in Poltergeist and click the LABEL in selenium to work. 我必须在Poltergeist中将INPUT设置为true,然后单击硒中的LABEL才能工作。

This is to select a radio button. 这是选择单选按钮。

I would like one method that worked in both. 我想两种方法都能奏效。 Any advice would be appreciated. 任何意见,将不胜感激。

It looks like you're passing XPath selectors to #find while telling it they are css -- its pure chance either of those works - you probably want 看起来您正在将XPath选择器传递给#find同时告诉他们它们是#find这完全是偶然的机会-您可能想要

find(:css, 'input#component_1').set(true)

or just 要不就

check('component_1')  # I'm assuming this is a checkbox due to setting true/clicking label being enough

if the checkbox is hidden then you won't be able to set it in which case you should be able to do the following 如果该复选框处于隐藏状态,则您将无法进行设置,在这种情况下,您应该可以执行以下操作

find(:css, 'label[for=component_1]').click

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM