F
F
fanat1k2018-04-15 10:29:30
ruby
fanat1k, 2018-04-15 10:29:30

How to login to adidas.ru using Ruby + Mechanize?

Can't login to https://www.adidas.ru/on/demandware.store/Sites-ad... . Even when submitting an empty form, after which the site is expected to say something like: "enter login / password", adidas redirects to the main page. Can you suggest what I'm doing wrong?

require 'rubygems'
  require 'nokogiri'
  require 'mechanize'
  require 'open-uri'

 def login_to_adidas
    url = 'https://adidas.ru/on/demandware.store/Sites-adidas-RU-Site/ru_RU/MyAccount-CreateOrLogin'
    agent = Mechanize.new
    agent.user_agent_alias = 'Linux Mozilla'
   
    agent.get(url) do |page|
        form = page.form(id: "dwfrm_login")
        form.field_with(name: "dwfrm_login_username").value = "[email protected]"
        form.field_with(name: "dwfrm_login_password").value = "adidaspassword"
        next_page = form.submit  #не логинтся, а редиректит на главную
    end
end

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
oh_shi, 2018-04-15
@oh_shi

Mechanize does not know how to interact with javascript. If it is important to imitate user actions, then try Capybara + PhantomJS instead. Or look at what JS sends requests and use them directly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question