Capybara select2 helper [closed]

匿名 (未验证) 提交于 2019-12-03 09:14:57

问题:

Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields.

See code below.

回答1:

module Features   module CapybaraHelpers     def select2(value, element_selector)       select2_container = first("#{element_selector}")       select2_container.find(".select2-choice").click        find(:xpath, "//body").find("input.select2-input").set(value)       page.execute_script(%|$("input.select2-input:visible").keyup();|)       drop_container = ".select2-results"       find(:xpath, "//body").find("#{drop_container} li", text: value).click     end   end end 

Then in your code just call something like select2("apple", "#s2id_fruit_id") and capybara will select "apple" value in select2 field with #s2id_fruit_id id.

Thanks to goodwill with his capybara-select2 gem.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!