简体   繁体   English

Cabybara根据元素名称查找元素

[英]Cabybara find element based on element name

Hi i am trying to select input field and add value into stripe's iframe, based on element name. 嗨,我正在尝试选择输入字段,并根据元素名称将值添加到Stripe的iframe中。 this won't work 这行不通

page.find(:name, 'exp-date')

i was able to select root div with id selector, but i can't select input field which is child node somewhere in root div 我能够使用id选择器选择root div,但是我无法选择root div中某个子节点的输入字段

  find(:id, "root")

Any idea how to target those fields 任何想法如何针对这些领域

Use the capybara find_field method to find field inputs. 使用find_field方法查找字段输入。 Checkout the docs here: http://www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Finders#find_field-instance_method 在此处签出文档: http : //www.rubydoc.info/github/jnicklas/capybara/Capybara/Node/Finders#find_field-instance_method

Would look something like: find_field('attributes[form_field_attribute_you_need]') 看起来像: find_field('attributes[form_field_attribute_you_need]')

Not sure if this works with an iframe, but you should be able to use: 不知道这是否适用于iframe,但是您应该可以使用:

within('#target_form_id') do #or another selector
  fill_in 'field_name_or_id', with: 'value'
  fill_in 'another_field', with: 'another_value'
end

您可以在此处使用CSS选择器:

find('input[name="exp-date"]', match: :first).set('my value')

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

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