简体   繁体   中英

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

I use Capybara as a driver in my auto tests. 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") ). 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) . But error occurs that says that " page " is not defined method.

The question is how to use Selenium methods with defined Capybara driver?

May be it is necessary to define Capybara driver in another way in order to successfully use " page.driver.browser " construction? Please provide little instance to see full picture.

page is just a convenience method in the 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

If you don't want to include the Capybara DSL into your tests you can also just use

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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