tuco_tuco icon indicating copy to clipboard operation
tuco_tuco copied to clipboard

Trouble with login form

Open dgoldie opened this issue 11 years ago • 5 comments

I'm trying to work with an external site to scrape data. The data is unique per user, so I need to login. When I click the submit button with tucotuco, the resulting page is wrong. I'm not logged in. The form in question has a lot of hidden fields. Could that be an issue?

Here's a gist of an iex session. https://gist.github.com/dgoldie/52fc48132aceff96e787 Am I doing something wrong?

thanks, -doug.

To see the correct actions, manually:

The login form is at: "http://games.espn.go.com/ffl/signin" I have a dummy account: username: "cookiemonsters20" password: "password1"

you'll know you're logged if:

  1. you see at the top "Jonathan, Active Insider"
  2. you see a section on the right labeled "MY TEAMS" with two teams listed, each with two links. One is "The Kerber League"

dgoldie avatar Oct 29 '14 16:10 dgoldie

I get this:

Interactive Elixir (1.0.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> use TucoTuco.DSL
:ok
iex(2)> TucoTuco.start_session :test_browser, :tuco_test, :phantomjs
{:ok,
 %TucoTuco.SessionPool.SessionPoolState{app_root: nil,
  current_session: :tuco_test, max_retry_time: 2000, retry_delay: 50,
  use_retry: false}}
iex(3)> visit "http://games.espn.go.com/ffl/signin"
{:ok,
 %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"url\":\"http://games.espn.go.com/ffl/signin\"}",
   headers: ["Content-Type": "application/json;charset=UTF-8",
    "Content-Length": 45], method: :POST,
   url: "http://localhost:51536/wd/hub/session/a331a610-5fca-11e4-a22e-43b41d396fc3/url"},
  session_id: "a331a610-5fca-11e4-a22e-43b41d396fc3", status: 0, value: %{}}}
iex(4)> fill_in "username", "cookiemonsters20"
{:error, "No field found with id, name or label specified"}
iex(5)> 

For me the username field is an input with no type attribute, so Finder.find :fillable_field, ... does not find it. Use Element.value/2 to fill it. eg Element.value input_element, "cookiemonsters20"

Also the password field was not getting filled: fixed in 0.7.1.

I'm not sure what exactly is happening in your trace. Can you run it with Firefox or Chrome and see if the fields are actually getting filled in correctly? (Or use save_screenshot with phantomjs.)

stuart avatar Oct 30 '14 02:10 stuart

screenshots....cool, I'll try that ...may not be until Friday.

sorry, I forgot to mention I got it to work by removing @type='text' in finder.ex #line 50 MDN says type is an optional attribute for input; the default value is 'text' if its not present. https://developer.mozilla.org/en-US/docs/Web/HTML/Element/Input so, you might want a different test.

btw: after this change, I thought the password field was filled. Well, just using Finder and Element to get the value.

  def find :fillable_field, term do
    # case find :xpath, "//input[@type='text' and (@name='#{term}' or @id='#  {term}')] | \
    case find :xpath, "//input[@name='#{term}' or @id='#{term}'] | \
    //textarea[@name='#{term}' or @id='#{term}']" do
      nil     -> find :field_for_label, term
      element -> element
    end
  end

dgoldie avatar Oct 30 '14 06:10 dgoldie

You are right, the usual thing is to default to a text input. There's a bunch of other HTML5 input types too that could be considered fillable. I will have to change that.

You would get an error if the password field did not fill, so from the gist that looked like it worked. I have it working in Firefox, Phantomjs is being temperamental.

stuart avatar Oct 30 '14 21:10 stuart

Still doesn't work. ...though the screenshot show a nice page. just not logged in. :-) updated to 0.7.1

also tried firefox, but it barfs (I did do the webdriver.firefox.install)

see errors: https://gist.github.com/dgoldie/13564e431d303fb63c84

dgoldie avatar Oct 31 '14 19:10 dgoldie

Firefox was dying because the plugin was out of date. I'm a bit stuck with Firefox versions as there are different versions of the webdriver.xpi plugin from Selenium that work with various Firefox versions.

stuart avatar Dec 21 '15 20:12 stuart