Created
June 28, 2020 07:49
-
-
Save XYenon/79317d63e7f769e5bdff5b595d709b65 to your computer and use it in GitHub Desktop.
heu-daily-checkin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# frozen_string_literal: true | |
require 'watir' | |
USERNAME = 'stu_num' | |
PASSWORD = 'passwd' | |
puts '=========================' | |
browser = Watir::Browser.new :chrome, headless: true | |
browser.goto 'http://ehome.hrbeu.edu.cn/' | |
def login(browser, username, password) | |
browser.text_field(id: 'username').set username | |
browser.text_field(id: 'password').set password | |
browser.button(name: 'submit').click | |
end | |
# First login | |
login(browser, USERNAME, PASSWORD) | |
puts 'First login success' | |
# Second login | |
browser.goto 'https://one.wvpn.hrbeu.edu.cn/infoplus/form/JKXXSB/start' | |
login(browser, USERNAME, PASSWORD) | |
puts 'Second login success' | |
# Wait for loading | |
browser.wait_until do |b| | |
b.div(id: 'div_loader').style.include?('display: none;') | |
end | |
puts 'Form loaded' | |
# Select the checkbox | |
cb = browser.checkbox(id: 'V1_CTRL82') | |
cb.set unless cb.set? | |
puts 'Checkbox checked' | |
# Submit | |
browser.link(text: '确认填报').click | |
sleep 5 | |
browser.button(text: '好').click | |
puts 'Submitted' | |
sleep 5 | |
browser.button(text: '确定').click | |
# Check success | |
browser.refresh | |
browser.wait_until do |b| | |
b.div(id: 'div_loader').style.include?('display: none;') | |
end | |
puts browser.div(id: 'title_content').text | |
if browser.div(id: 'title_content').text.include?('已完成') | |
puts 'Success' | |
else | |
puts 'Fail' | |
end | |
puts 'Done at ' + Time.now.to_s | |
browser.close | |
puts '=========================' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment