Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I extract the Selenium Element from a Capybara Element?

I am more familiar with Java and Selenium than Ruby and Capybara and SitePrism, so apologies if this question is rather thick.

Selenium has a very useful class for managing Select tags, Selenium::WebDriver::Support::Select, which can be created by passing it the Selenium Element (Selenium::WebDriver::Element) representing the select. I would like to get a Select object so I can use its convenient methods.

Using SitePrism and Capybara, however, the standard method of defining elements gives me access to a select modeled by Capybara's Element class, Capybara::Node::Element, and I can't seem to find an easy way to extract the underlying Selenium Element from the Capybara Element.

I've searched around for alternatives and found Capybara's #select method, but that seems very limiting to me, since it looks like it forces you to select by value and has very narrow parameters for defining the select on the page.

Is there an easy way to create a Selenium Select from SitePrism/Capybara? Or is there a better way of doing this entirely? Thanks!

like image 256
James Martineau Avatar asked Sep 10 '13 18:09

James Martineau


1 Answers

Ah, I found it. It was right in Capybara::Node::Element all along. The #native method returns the native element from the driver. This can then be passed into the Selenium Select's initialize method to successfully create the Select.

like image 172
James Martineau Avatar answered Nov 16 '22 02:11

James Martineau