vamsiikrishna's solution to "ruby script that logs in to twitter and updates profile picture"

require<\/span> <\/span>'watir-webdriver'<\/span>\n\n#<\/span> <\/span>update<\/span> <\/span>with<\/span> <\/span>your<\/span> <\/span>credentials<\/span>\nusername<\/span> <\/span>=<\/span> <\/span>&<\/span>quot<\/span>;<\/span>username&quot<\/span>;<\/span>\npassword<\/span> <\/span>=<\/span> <\/span>&<\/span>quot<\/span>;<\/span>pass&quot<\/span>;<\/span>\nphoto<\/span> <\/span>=<\/span> <\/span>&<\/span>quot<\/span>;<\/span>/<\/span>path<\/span>/<\/span>to<\/span>/<\/span>photo<\/span>.<\/span>jpeg&quot<\/span>;<\/span>\n\n\nb<\/span> <\/span>=<\/span> <\/span>Watir:<\/span>:<\/span>Browser<\/span>.<\/span>new<\/span> <\/span>:<\/span>chrome<\/span>\n\nb<\/span>.<\/span>goto<\/span> <\/span>'twitter.com'<\/span>\n\nb<\/span>.<\/span>text_field<\/span>(<\/span>:<\/span>id<\/span> <\/span>=><\/span> <\/span>'signin-email').set username<\/span>\nb<\/span>.<\/span>text_field<\/span>(<\/span>:<\/span>id<\/span> <\/span>=><\/span> <\/span>'signin-password').set password<\/span>\nb<\/span>.<\/span>button<\/span>(<\/span>:<\/span>class<\/span> <\/span>=><\/span> <\/span>'submit btn primary-btn flex-table-btn js-submit').click<\/span>\n\nb<\/span>.<\/span>goto<\/span> <\/span>'twitter.com/settings/profile'<\/span>\nsleep<\/span>(<\/span>5<\/span>)<\/span>\nb<\/span>.<\/span>button<\/span>(<\/span>:<\/span>id<\/span> <\/span>=><\/span> <\/span>'profile_image_upload').click<\/span>\nb<\/span>.<\/span>file_field<\/span>(<\/span>:<\/span>name<\/span>,<\/span> <\/span>&<\/span>quot<\/span>;<\/span>media<\/span>[]<\/span>&<\/span>quot<\/span>;)<\/span>.<\/span>set<\/span> <\/span>photo<\/span>\nl<\/span> <\/span>=<\/span> <\/span>b<\/span>.<\/span>link<\/span> <\/span>:<\/span>text<\/span> <\/span>=><\/span> <\/span>'Save'<\/span>\nl<\/span>.<\/span>exists<\/span>?<\/span>\nl<\/span>.<\/span>click<\/span>\n<\/pre><\/div>
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 was kinda stuck for few mins with the upload part, documentation ftw !

User: vamsiikrishna

Question: ruby script that logs in to twitter and updates profile picture

Back to question