Skip to content

Instantly share code, notes, and snippets.

@kejadlen
Created January 5, 2018 05:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kejadlen/e9861c8a7c73193a4f6a06cd24fc0949 to your computer and use it in GitHub Desktop.
Save kejadlen/e9861c8a7c73193a4f6a06cd24fc0949 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "io/console"
require "capybara"
require "capybara/dsl"
require "selenium-webdriver"
require "pry"
print "Username: "
username = gets.chomp
print "Password: "
password = STDIN.noecho(&:gets).chomp
Capybara.register_driver :selenium do |app|
options = Selenium::WebDriver::Chrome::Options.new
options.add_preference("download.default_directory", __dir__)
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
end
Capybara.default_driver = :selenium
Capybara.default_max_wait_time = 5
verbose, $VERBOSE = $VERBOSE, nil
include Capybara::DSL
$VERBOSE = verbose
visit "https://chase.com"
within_frame(find("#logonbox")) do
fill_in "Username", with: username
fill_in "Password", with: password
sleep 0.1 # 💩
click_on "Sign in"
end
raise "Couldn't log in" unless find "#logonDetailsContainer"
find("h3", text: "CREDIT CARDS")
.find(:xpath, "../..")
.first(".account-tile")
.click
find("h1#accountName", text: "CREDIT CARD")
find("#creditCardTransTable") {|table| table.find_all("tr").size > 2 }
click_link "downloadActivityIcon"
click_button "Current display, including filters"
click_link "Choose a date range"
# TODO
fill_in "accountActivityFromDate", with: "01/01/2018"
fill_in "accountActivityToDate", with: "01/04/2018"
find("body").click # defocus input field
click_on "Download"
while Dir.glob("*.csv", File::FNM_CASEFOLD).empty?
end
binding.pry
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment