[英]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.