简体   繁体   English

如何使用Ruby调用定义的Capybara驱动程序的Selenium方法?

[英]How to call Selenium methods with defined Capybara driver using Ruby?

I use Capybara as a driver in my auto tests. 我在自动测试中使用Capybara作为驱动程序。 I defined a driver as: Capybara.default_driver = :selenium But it is impossible to use Selenium methods in usual way (like: @driver.find_element(:xpath, ::Login_button).send_keys("MY_login") ). 我将驱动程序定义为: Capybara.default_driver =:selenium但是不可能以通常的方式使用Selenium方法(例如: @ driver.find_element(:xpath,:: Login_button).send_keys(“MY_login”) )。 I saw on some resources that it is possible to call Selenium methods using construction: page.driver.browser For instance: element = page.driver.browser.find_element(:id, ell) . 我在一些资源上看到可以使用构造调用Selenium方法: page.driver.browser例如: element = page.driver.browser.find_element(:id,ell) But error occurs that says that " page " is not defined method. 但是出现错误,表示“ 页面 ”未定义方法。

The question is how to use Selenium methods with defined Capybara driver? 问题是如何使用定义的Capybara驱动程序的Selenium方法?

May be it is necessary to define Capybara driver in another way in order to successfully use " page.driver.browser " construction? 可能有必要以另一种方式定义Capybara驱动程序,以便成功使用“ page.driver.browser ”构造? Please provide little instance to see full picture. 请提供一些实例来查看全貌。

page is just a convenience method in the Capybara DSL for Capybara.current_session . page只是Capybara DSL for Capybara.current_session的便捷方法。 You can use 'page' if you've included Capybara::DSL into the scope of your tests - see https://github.com/jnicklas/capybara#using-capybara-with-testunit 如果您已将Capybara :: DSL纳入测试范围,则可以使用“page” - 请参阅https://github.com/jnicklas/capybara#using-capybara-with-testunit

If you don't want to include the Capybara DSL into your tests you can also just use 如果您不想将Capybara DSL包含在测试中,您也可以使用

Capybara.current_session.driver.browser ....

although accessing selenium methods directly should only be done when absolutely necessary and there isn't a cross driver way to do what you want provided by Capybara 虽然直接访问selenium方法只能在绝对必要的时候进行,并且没有交叉驱动方式来做你想要的Capybara提供的东西

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

相关问题 如果定义了Capybara Poltergeist驱动程序(对于Ruby),如何访问Selenium方法 - How to access Selenium methods if I defined Capybara Poltergeist driver (for Ruby) 如何使用Capybara和Selenium Web驱动程序发送密钥 - How do I send keys using Capybara with selenium web driver 如何使用硒红宝石水豚从悬停下拉列表中选择一个值 - how to select a value from hover dropdown using selenium ruby capybara Capybara / Selenium-在每次调用时强制重新加载Selenium Driver - Capybara/Selenium - force to reload Selenium Driver on each call 使用水豚在硒红宝石中悬停鼠标 - Mouse Hover in selenium Ruby using capybara 如何使用 Selenium 在 Ruby Capybara 中启用 ChromeDriver 日志记录? - How to enable ChromeDriver logging in Ruby Capybara with Selenium? 如何在ruby中调用一系列模块中定义的超级方法 - How to call super methods defined in a serial of modules in ruby 如何在Ruby子类中的动态定义方法上调用super? - How to call super on dynamicly defined methods in sub-classes in Ruby? 如何在Ruby中使用Selenium Web驱动程序加载自定义Chrome扩展程序? - How to load custom chrome extension using selenium web driver in ruby? 将模块中定义的方法与Ruby中的类方法一起使用 - Using methods defined in a module with class methods in Ruby
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM