0

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.

Jonathan Tuzman
  • 11,568
  • 18
  • 69
  • 129
  • There is something simple, just use Mechanize#post to post the form data to that url. Look in chrome network tab to see what the request looks like. – pguardiario Nov 18 '18 at 23:53

2 Answers2

1

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

hernanvicente
  • 914
  • 8
  • 18
0

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.

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78