Skip to content

Instantly share code, notes, and snippets.

@michaelminter
Created October 18, 2012 15:29
Show Gist options
  • Save michaelminter/3912576 to your computer and use it in GitHub Desktop.
Save michaelminter/3912576 to your computer and use it in GitHub Desktop.

Revisions

  1. michaelminter revised this gist Oct 20, 2012. 1 changed file with 31 additions and 0 deletions.
    31 changes: 31 additions & 0 deletions twitter.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    #!/usr/bin/ruby
    require 'rubygems'
    require 'watir-webdriver'

    o = [('a'..'z'),('A'..'Z'),(0..9)].map{|i| i.to_a}.flatten
    string = (0...8).map{ o[rand(o.length)] }.join

    # settings
    username = "[email protected]"
    password = "password"
    imagepath = "/assets/locations/github.gif"

    # create new instance
    browser = Watir::Browser.new
    browser.goto "https://twitter.com/"

    # login
    browser.text_field(:id => "signin-email").set username
    browser.text_field(:id => "signin-password").set password
    browser.button(:class => "js-submit").click

    # change profile settings
    browser.goto "https://twitter.com/settings/password"
    # sleep(2)
    browser.text_field(:id => 'current_password').set password
    browser.text_field(:id => 'user_password').set string
    browser.text_field(:id => 'user_password_confirmation').set string
    browser.button(:id => "settings_save").click
    # sleep(2)
    puts browser.text.include? 'Your password has been changed'
    puts string
  2. michaelminter revised this gist Oct 18, 2012. 1 changed file with 20 additions and 18 deletions.
    38 changes: 20 additions & 18 deletions watir.rb
    Original file line number Diff line number Diff line change
    @@ -1,23 +1,25 @@
    #!/usr/bin/ruby
    require 'rubygems'
    require 'watir-webdriver'

    # update with your credentials
    username = "username"
    password = "pass"
    photo = "/path/to/photo.jpeg"
    # settings
    username = "USERNAME"
    password = "PASSWORD"
    imagepath = "/Users/alex/image.png"

    # create new instance
    browser = Watir::Browser.new
    browser.goto "https://twitter.com/"

    b = Watir::Browser.new :chrome
    # login
    browser.text_field(:id => "signin-email").set username
    browser.text_field(:id => "signin-password").set password
    browser.button(:class => "js-submit").click

    b.goto 'twitter.com'

    b.text_field(:id => 'signin-email').set username
    b.text_field(:id => 'signin-password').set password
    b.button(:class => 'submit btn primary-btn flex-table-btn js-submit').click

    b.goto 'twitter.com/settings/profile'
    sleep(5)
    b.button(:id => 'profile_image_upload').click
    b.file_field(:name, "media[]").set photo
    l = b.link :text => 'Save'
    l.exists?
    l.click
    # change profile settings
    browser.goto "https://twitter.com/settings/profile"
    sleep(1)
    browser.button(:id => "profile_image_upload").click
    browser.file_field(:class => "file-input").send_keys(imagepath)
    sleep(2)
    browser.link(:text => "Save").click
  3. michaelminter created this gist Oct 18, 2012.
    23 changes: 23 additions & 0 deletions watir.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    require 'watir-webdriver'

    # update with your credentials
    username = "username"
    password = "pass"
    photo = "/path/to/photo.jpeg"


    b = Watir::Browser.new :chrome

    b.goto 'twitter.com'

    b.text_field(:id => 'signin-email').set username
    b.text_field(:id => 'signin-password').set password
    b.button(:class => 'submit btn primary-btn flex-table-btn js-submit').click

    b.goto 'twitter.com/settings/profile'
    sleep(5)
    b.button(:id => 'profile_image_upload').click
    b.file_field(:name, "media[]").set photo
    l = b.link :text => 'Save'
    l.exists?
    l.click
    23 changes: 23 additions & 0 deletions watir2.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    require 'watir-webdriver'

    # update with your credentials
    username = "username"
    password = "pass"
    photo = "/path/to/photo.jpeg"


    b = Watir::Browser.new :chrome

    b.goto 'twitter.com'

    b.text_field(:id => 'signin-email').set username
    b.text_field(:id => 'signin-password').set password
    b.button(:class => 'submit btn primary-btn flex-table-btn js-submit').click

    b.goto 'twitter.com/settings/profile'
    sleep(5)
    b.button(:id => 'profile_image_upload').click
    b.file_field(:name, "media[]").set photo
    l = b.link :text => 'Save'
    l.exists?
    l.click