Class: HsbcLatestDownload::Download

Inherits:
Object
  • Object
show all
Defined in:
lib/hsbc_latest_download/download.rb

Constant Summary collapse

HSBC_URL =
'https://www.hsbc.co.uk/'

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Download

Returns a new instance of Download.



7
8
9
# File 'lib/hsbc_latest_download/download.rb', line 7

def initialize(options)
  @options = options
end

Instance Method Details

#password_character(number) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/hsbc_latest_download/download.rb', line 56

def password_character(number)
  if number <= 6
    return @options[:password][number-1, 1]
  elsif number == 7
    # second to last character
    return @options[:password][@options[:password].length-2, 1]
  else
    # last character
    return @options[:password][@options[:password].length-1, 1]
  end
end

#run!Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/hsbc_latest_download/download.rb', line 11

def run!
  driver = Selenium::WebDriver.for :chrome
  driver.navigate.to HSBC_URL

  wait = Selenium::WebDriver::Wait.new(:timeout => 10)

  driver.find_element(partial_link_text: 'Log on').click

  element = driver.find_element(:name, 'userid')
  element.send_keys @options[:username]
  element.submit

  driver.find_element(partial_link_text: 'Without Secure Key').click

  driver.find_element(name: 'memorableAnswer').send_keys(@options[:memorable_answer])

  (1..8).each do |char|
    field = driver.find_element(name: "pass#{char}")
    unless field.attribute('disabled')
      letter = password_character(char)
      field.send_keys(letter)
    end
  end

  driver.find_element(class: 'submit_input').click

  wait.until { driver.find_element(:partial_link_text =>  @options[:account_name]) }
  sleep 1
  driver.find_element(:partial_link_text, @options[:account_name]).click

  wait.until { driver.find_element(:partial_link_text =>  'Download') }
  driver.find_element(:partial_link_text, 'Download').click

  within_modal = "//div[contains(concat(' ',normalize-space(@class),' '),' dijitDialogFixed ')]"
  wait.until { driver.find_element(:xpath =>  "#{within_modal}//input[@value='ofx']") }
  driver.find_element(:xpath, "#{within_modal}//input[@value='ofx']").click

  driver.find_element(:xpath, "#{within_modal}//button[@data-dojo-attach-point='dapDownloadBtn']").click

  sleep 10

  driver.find_element(partial_link_text: 'Log off').click
  driver.quit
end