Skip to content

Instantly share code, notes, and snippets.

@dgoldie
Last active August 29, 2015 14:08
Show Gist options
  • Save dgoldie/52fc48132aceff96e787 to your computer and use it in GitHub Desktop.
Save dgoldie/52fc48132aceff96e787 to your computer and use it in GitHub Desktop.
Using TucoTuco with login form
Interactive Elixir (1.0.1-dev) - 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:58561/wd/hub/session/2fc47970-5f82-11e4-a887-c7a70ffba64f/url"},
session_id: "2fc47970-5f82-11e4-a887-c7a70ffba64f", status: 0, value: %{}}}
iex(4)> fill_in "username", "cookiemonsters20"
{:ok,
%WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"value\":[\"c\",\"o\",\"o\",\"k\",\"i\",\"e\",\"m\",\"o\",\"n\",\"s\",\"t\",\"e\",\"r\",\"s\",\"2\",\"0\"]}",
headers: ["Content-Type": "application/json;charset=UTF-8",
"Content-Length": 75], method: :POST,
url: "http://localhost:58561/wd/hub/session/2fc47970-5f82-11e4-a887-c7a70ffba64f/element/:wdc:1414597363219/value"},
session_id: "2fc47970-5f82-11e4-a887-c7a70ffba64f", status: 0, value: nil}}
iex(18)> fill_in "password", "password1"
{:ok,
%WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"value\":[\"p\",\"a\",\"s\",\"s\",\"w\",\"o\",\"r\",\"d\",\"1\"]}",
headers: ["Content-Type": "application/json;charset=UTF-8",
"Content-Length": 47], method: :POST,
url: "http://localhost:58561/wd/hub/session/2fc47970-5f82-11e4-a887-c7a70ffba64f/element/:wdc:1414597363229/value"},
session_id: "2fc47970-5f82-11e4-a887-c7a70ffba64f", status: 0, value: nil}}
iex(19)> click_button "Sign In"
{:ok,
%WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{}",
headers: ["Content-Type": "application/json;charset=UTF-8",
"Content-Length": 2], method: :POST,
url: "http://localhost:58561/wd/hub/session/2fc47970-5f82-11e4-a887-c7a70ffba64f/element/:wdc:1414597363230/click"},
session_id: "2fc47970-5f82-11e4-a887-c7a70ffba64f", status: 0, value: %{}}}
iex(20)>
iex(21)> Page.has_text? "The Kerber League"
false
iex(30)> Finder.find(:xpath, "//html/body") |> Element.text
"Sign In or Register\nEDITIONS:\nUSA\nDEPORTES\nMore\nCITIES:\nBOSTON\nCHICAGO\nDALLAS\nLOS ANGELES\nNEW YORK\nESPN\nShop\nTOP STORIES\nSPORTSCENTER VIDEOS\nFree-Agent Finds\nIf the six-team bye week has you concerned, Christopher Harris is here to help. Free-agent finds »\nBerry: Week 9 TMR200 ranks »Williamson: Long-term pickups Underground podcast\nJason Bridge/USA TODAY Sports\nFree Agents\nUpside WRs\nFantasy 32\nInjury Updates\nFantasy Fallout\nYou need to have the Adobe Flash Player to view this content.\nPlease click here to continue.\nMATTHEW BERRY\nEarly look at Week 9\n• TMR200 rankings\n• Top wide receiver fill-ins\nLeave feedback for the TMR\nBackfield breakdown entering Week 9\n2014 rankings update: New No. 1 at WR, TE\nFour Downs: Patriots offense rollin' now\nWeek 8 flex rankings\nWEEKLY CONTENT\nWednesday\nWeek 9 Rankings - ESPN Fantasy Staff\nTop 200 for Week 9 - Matthew Berry\nWeek 8 ranks reaction - Eric Karabell\nWeek 9 projections - ESPN Fantasy staff\nTrendspotting - Ken Daube\nInjury updates - Stephania Bell\nSalary-cap targets - Football Outsiders\nHigh-upside wideouts - Berry/Saturday\nFantasy Focus podcast\nEric Karabell chat, 11 a.m. ET\nMatt Williamson chat, Noon ET\nTuesday\nMonday\nWeekend\nFriday\nThursday\nFANTASY FOOTBALL PODCASTS\nFantasy Focus Football - Time To Drop Vincent Jackson?\nPlay Podcast\nMatthew Berry and Nate Ravitz discuss waiver wire options for Week 9 and 10 bye weeks. Plus, a healthy dose of mailbag questions with a sprinkle of non-sense.\nFantasy Focus Football - Week 9 Waiver Pickups\nFantasy Underground - Patriot Games\nFantasy Focus Football - Big Ben's Big Night\nFantasy Focus Football - Week 8 Preview\nFantasy Focus Football - Is Wes Welker Droppable?\nFantasy Underground - Mid-season Undies\nFantasy Focus Football - Nat Coombs\nMore Podcasts »\nMUST-WATCH VIDEOS\nWide receiver fill-ins\nMatthew Berry names three wide receivers worth picking up off the waiver wire this week.\nRonnie Hillman\nEric Karabell discusses why Ronnie Hillman is a must-add in all leagues.\nJonas Gray\nEric Karabell says why the Patriots' Jonas Gray is such an intriguing pick-up this week.\nFANTASY FOOTBALL COLUMNISTS\nChristopher Harris\nFree-agent finds: Week 9\nMatthew Berry\nTMR200 for Week 9\nEric Karabell\nFour Downs | 2014 ranks update\nMike Clay\n32 tips for Week 9\nMatt Williamson\nLong-term pickup targets: Week 9\nTristan H. Cockcroft\nBig Ben's near-historic day\nKC Joyner\nTrade targets for fantasy playoffs\nJim McCormick\nWeek 8 IDP rankings\nKen Daube\nKey trends entering Week 8\nStephania Bell\nLatest injury updates\nFREE GAMES TO PLAY\nGridiron Challenge\nBuild a team under the salary cap or play it Eliminator style.\nPigskin Pick'em\nPick the winner of each NFL game, straight up or against the spread.\nEliminator\nPick one NFL winner a week, but you can't use the same team twice!\nCollege FB Challenge\nAll the conferences. All the players. Create the best roster today.\nCollege Pick 'em\nBe confident in your college football picks each week.\nMY TEAMS\nFOOTBALL\nFantasy Football\nSign Up Today!\nQUICK LINKS\nESPN Fantasy on Facebook\nESPN Fantasy on Twitter\nDownload the ESPN Fantasy Football App\nFantasy video analysis\nNFL home\nNFL stats\nRumor Central\nRotopass\nFind Tickets:\nSelect One\n\n 49ers\n Bears\n Bengals\n Bills\n Broncos\n Browns\n Buccaneers\n Cardinals\n Chargers\n Chiefs\n Colts\n Cowboys\n Dolphins\n Eagles\n Falcons\n Giants\n Jaguars\n Jets\n Lions\n Packers\n Panthers\n Patriots\n Raiders\n Rams\n Ravens\n Redskins\n Saints\n Seahawks\n Steelers\n Texans\n Titans\n Vikings\n \nBuy NFL Tickets and all other Football Tickets at StubHub!\nSee all tickets\nMyESPN\nNFL\nMLB\nNBA\nNHL\nNCAAF\nNCAAM\nNASCAR\nSOCCER\nMORE SPORTS\nRADIO\n& MORE\nespnW\n& X GAMES\nFANTASY\n& GAMES\nWATCH\nFantasy Football\nProjections\nAdded/Dropped\nWeekly Rankings\nConsistency Ratings\nRB Chart\nScoring Leaders\nApps\nFAQ\nToolkit\nMore\nESPN.com: Help | Press | Advertise On ESPN.com | Sales Media Kit | Interest-Based Ads | Report a Bug | Corrections | Contact Us | Site Map | Shop | Jobs | Patents | Supplier Information\n©2014 ESPN Internet Ventures. Terms of Use and Privacy Policy and Safety Information/Your California Privacy Rights are applicable to you. All rights reserved."
iex(31)>
@stuart
Copy link

stuart commented Oct 30, 2014

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, so Finder.find :fillable_field, ... does not find it. Maybe I should fix that so that fields with no type are fillable.

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
Copy link

stuart commented Oct 30, 2014

I also just worked out that fill_in is probably not going to work with password fields. I will fix that, pronto.

You may be able to work around with Element.value/2 http://hexdocs.pm/webdriver/0.7.0/WebDriver.Element.html#value/2

@stuart
Copy link

stuart commented Oct 30, 2014

iex(1)> use TucoTuco.DSL
:ok
iex(2)>  TucoTuco.start_session :test_browser, :tuco_test, :firefox
{: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:54816/hub/session/2adb0af1-8a88-7447-ac71-6a6326a77816/url"},
  session_id: "2adb0af1-8a88-7447-ac71-6a6326a77816", status: 0, value: ""}}
iex(4)> fill_in "username", "cookiemonsters20"
{:ok,
 %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"value\":[\"c\",\"o\",\"o\",\"k\",\"i\",\"e\",\"m\",\"o\",\"n\",\"s\",\"t\",\"e\",\"r\",\"s\",\"2\",\"0\"]}",
   headers: ["Content-Type": "application/json;charset=UTF-8",
    "Content-Length": 75], method: :POST,
   url: "http://localhost:54816/hub/session/2adb0af1-8a88-7447-ac71-6a6326a77816/element/%7Bfeb4183f-650c-524a-a458-153bce646224%7D/value"},
  session_id: "2adb0af1-8a88-7447-ac71-6a6326a77816", status: 0, value: ""}}
iex(5)> fill_in "password", "password1"
{:ok,
 %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{\"value\":[\"p\",\"a\",\"s\",\"s\",\"w\",\"o\",\"r\",\"d\",\"1\"]}",
   headers: ["Content-Type": "application/json;charset=UTF-8",
    "Content-Length": 47], method: :POST,
   url: "http://localhost:54816/hub/session/2adb0af1-8a88-7447-ac71-6a6326a77816/element/%7B3609ea2f-e722-954c-9def-f12c3bc563b8%7D/value"},
  session_id: "2adb0af1-8a88-7447-ac71-6a6326a77816", status: 0, value: ""}}
iex(6)> click_button "Sign In"
{:stale_element_reference,
 %WebDriver.Protocol.Response{request: %WebDriver.Protocol.Request{body: "{}",
   headers: ["Content-Type": "application/json;charset=UTF-8",
    "Content-Length": 2], method: :POST,
   url: "http://localhost:54816/hub/session/2adb0af1-8a88-7447-ac71-6a6326a77816/element/%7Bc2969ef2-a3a8-c04f-90ea-12c677ffeefe%7D/click"},
  session_id: "2adb0af1-8a88-7447-ac71-6a6326a77816", status: 10,
  value: %{"message" => "Element not found in the cache - perhaps the page has changed since it was looked up",
    "stackTrace" => [%{"fileName" => "resource://fxdriver/modules/web_element_cache.js",
       "lineNumber" => 7610, "methodName" => "fxdriver.cache.getElementAt"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 7210, "methodName" => "Utils.getElementAt"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 8223, "methodName" => "fxdriver.preconditions.visible"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 10861,
       "methodName" => "DelayedCommand.prototype.checkPreconditions_"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 10878,
       "methodName" => "DelayedCommand.prototype.executeInternal_/h"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 10883,
       "methodName" => "DelayedCommand.prototype.executeInternal_"},
     %{"fileName" => "file:///var/folders/g7/x2l0dw_10bsg_8023c3y25fw0000gn/T/webdriver-firefox-profile2hha5unnuda/extensions/[email protected]/components/command_processor.js",
       "lineNumber" => 10825,
       "methodName" => "DelayedCommand.prototype.execute/<"}]}}}
iex(7)> Page.has_text? "The Kerber League"
true
iex(8)> 

Working for me on Firefox when I remove the requirement for a fillable field to be a text element.
I did get an error, it's the click_button which does a find_with_retry and halfway through the second retry the page changes, so Its not fatal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment