Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
seleniumでieyasu出勤、退勤するrubyスクリプトです
require "selenium-webdriver"
driver = Selenium::WebDriver.for :phantomjs
driver.navigate.to "https://ieyasu.co/company_name/login/" ## please change company_name
element = driver.find_element(:id, 'user_login_id')
element.send_keys ARGV[0]
element = driver.find_element(:id, 'user_password')
element.send_keys ARGV[1]
element.submit
if driver.current_url == 'https://ieyasu.co/timestamp'
puts 'ログインできました!^_^'
else
puts 'ログインできませんでした'
end
today_element = driver.find_element(:id => 'day')
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
begin
wait.until { element = driver.find_element(:id => "btnIN1") }
element.click
element = driver.find_element(:id => 'day')
puts "#{today_element.text}出勤しました!今日も頑張りましょう\(^o^)/"
rescue
begin
puts '出勤済なので退勤ボタンを押します(*´ω`*)'
wait.until { element = driver.find_element(:id => "btnIN2") }
element.click
puts "#{today_element.text}退勤しました!おつかれさまでした!(^^)"
rescue
puts '退勤できませんでした(泣)退勤済の可能性があります'
end
ensure
driver.quit
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment