Creating a browser automation tool with Ruby + Selenium

I made a tool to automate the work of just popping in order to take the class on a first-come, first-served basis when someone removes it in the lottery course of the university registration. I think that the method of registering for courses differs depending on the university, so I will only outline it. I used Ruby, SeleniumWebDriver, and the browser is Google Chrome.

What is Selenium

A tool that automatically operates (tests) web applications on a web browser.

What is Selenium Web Driver?

A mechanism to solve the problems of the old Selenium RC and operate the browser. Selenium RC is also called Selenium 1, and Selenium Web Driver is also called Selenium 2.

environment

$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.6
BuildVersion: 18G103

$ ruby -v
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-darwin18]

Install Selenium Web Driver

$ gem install selenium-webdriver

Added Selenium Web Driver gem in terminal.

$ gem list

If selenium-webdriver is displayed, it's OK!

Install Chrome Driver

This time we will use Google Chrome in the browser, so install Chrome Driver from the link below.

Chrome Driver

Sample code

I will write the code with an editor. I think that page transitions will differ depending on the university, so keep it simple. Since we are using Ruby this time, we will name it selenium_test.rb.

selenium_test.rb


require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome
driver.manage.timeouts.implicit_wait = 60
#Specify the waiting time until the specified driver element is found

driver.navigate.to "URL"
#Access by specifying the URL

driver.find_element(:xpath, 'Describe the corresponding xpath').click
#Specify a button with xpath and press

driver.find_element(:name 'The name attribute you want to specify').send_keys('The word you want to enter')
#Specify the input form of name attribute and enter characters.

#After that, please use if statement, loop statement, etc. and create it according to the course registration of each university.

driver.quit
#Close driver

Execute with the following command.

$ ruby selenium_test.rb

Please point out any strange points! !!

reference

Selenium cheat sheet

Recommended Posts

Creating a browser automation tool with Ruby + Selenium
Creating a Cee-lo game with Ruby 4th Creating a game progress process
Creating a calendar using Ruby
Ruby Scraping-Move Selenium Headless with VPS.
Make a slideshow tool with JavaFX
[Rails] Creating a new project with rails new
Creating a timer app with a muddy
Make a typing game with ruby
[Linux: Ruby] Use the driver with selenium without specifying the browser driver path
Let's make a smart home with Ruby!
I made a risky die with Ruby
Extract a part of a string with Ruby
Start with a browser Ruby game programming: Introduction to Nyle-canvas (DXRuby style)
Ruby programming with just a browser: "Breakout" (Nyle-canvas edition) that creates step by step
A story about creating a library that operates next-generation sequencer data with Ruby ruby-htslib
Escape processing when creating a URL in Ruby
AtCoder Beginner Contest 169 A, B, C with ruby
Access with Selenium as a countermeasure for navigator.webdriver
(Ruby on Rails6) Creating data in a table
Creating a common repository with Spring Data JPA
I made a portfolio with Ruby On Rails
Creating a Dockerfile with all AWS CloudFormation test tools
[Ruby] Generate a concatenated QR code with rqrcode (Knowledge)
Let's make a LINE Bot with Ruby + Sinatra --Part 2
[Ruby] I made a crawler with anemone and nokogiri.
[Ruby] Generate a concatenated QR code with rqrcode (Practice)
A memorandum when creating a REST service with Spring Boot
Let's make a LINE Bot with Ruby + Sinatra --Part 1
How to get started with creating a Rails app
Use Coveralls with GitHub Actions in a Ruby repository