How do I use Selenium with Ruby?


We can use Selenium with Ruby. First of all we have to install Ruby in the system. For installation in Windows, we have to take the help of the RubyInstaller package by navigating to the link −

https://rubyinstaller.org/

Click on Download.

The various versions of Ruby Installers links get displayed. Select the latest version and click on it.

Click on the Save File button to download the corresponding rubyinstaller.exe file.

Once the download is completed, accept the license agreement and proceed to the next steps till installation is completed.

To have Selenium webdriver package for Ruby, run the command −

gem install selenium−webdriver

To have Rest−Client package for Ruby, run the command −

gem install rest−client

To have test−unit package for Ruby, run the command −

gem install test−unit

Example

#set webdriver gem for Selenium
require "selenium−webdriver"
require "rubygems"
#driver object creation
driver = Selenium::WebDriver.for :chrome
#launch browser
driver.navigate.to "https://www.tutorialspoint.com/index.htm"
#close browser
driver.close

Updated on: 02-Feb-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements