Jonathan Tuzman
Jonathan Tuzman

Reputation: 13262

Mechanize can't find form

I'm having some problem accessing the form element on a page I'm getting using Mechanize.

username_page = agent.get 'https://member.carefirst.com/mos/#/home'
username_form = username_page.form_with(name: 'soloLoginForm')

username_form is nil. (username_page does have the page). The page definitely has a form and the field is #soloLoginForm, but username_page.body has no form element.

I'm guessing this is some async or dynamic issue. I'm able to grab the form with poltergeist, and I'm looking into doing all my form filling with capybara/poltergeist, but I wonder if there's something simple I'm missing that will allow me to use mechanize, as I'd planned.

Upvotes: 0

Views: 323

Answers (2)

Thomas Walpole
Thomas Walpole

Reputation: 49870

As stated in the answer by @hernanvicente the page is using Angular and requires JS (which mechanize does not support). However, you really want to be using selenium with headless Chrome rather than Poltergeist nowadays. Poltergeist is equivalent to about a 7 year old version of Safari (due to PhantomJS, which it uses for rendering, being abandoned) so it doesn't support a lot of JS and CSS used in modern sites. Another advantage of using Selenium with Chrome is that you can easily swap between headless and headed to see what's happening when you need to debug things.

Upvotes: 0

hrnnvcnt
hrnnvcnt

Reputation: 944

It seems to be that 'https://member.carefirst.com/mos/#/home' uses Angular to render elements of the page and AngularJS requires Javascript support in the browser or in your case Capybara needs a driver with Javascript support.

Mechanize doesn't support Javascript, check this old SO thread. This is probably the reason why it works when you try with poltergeist.

Check: https://github.com/teamcapybara/capybara#drivers

Upvotes: 1

Related Questions