To get started with Ruby and Selenium WebDriver, there are a few essential commands you should know. Here are some of the most important ones:

require 'selenium-webdriver'

This command is used to import the Selenium WebDriver library into your Ruby script. You need to include this command at the beginning of your script to be able to use Selenium WebDriver.

require 'selenium-webdriver'

driver = Selenium::WebDriver.for :chrome

This command creates a new instance of the Chrome browser that Selenium WebDriver can control. You can replace :chrome with the name of the browser you want to use, such as :firefox or :safari.

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome

driver.navigate.to

This command tells Selenium WebDriver to navigate to the specified URL in the browser.

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome

driver.navigate.to "https://www.google.co.uk/"

element = driver.find_element(:name, "q")

This command finds the first element on the page that matches the specified selector. In this example, we are searching for an element with the name “q”.

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome

driver.navigate.to "https://www.google.co.uk/"

element = driver.find_element(:name, "q")

element.send_keys "NASA"

This command sends the specified keys to the element. In this example, we are sending the text “Search Input” to the input field.

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome

driver.navigate.to "https://www.google.co.uk/"

element = driver.find_element(:name, "q")

element.send_keys "NASA"

search_button = driver.find_element(name: 'btnK')

This command finds the search button element using its name attribute and clicks it using the click method.

require 'selenium-webdriver'


driver = Selenium::WebDriver.for :chrome

driver.navigate.to "https://www.google.co.uk/"

element = driver.find_element(:name, "q")

element.send_keys "NASA"

search_button = driver.find_element(name: 'btnK')

search_button.click()

These are just a few of the essential commands you need to know to get started with Ruby and Selenium WebDriver. By mastering these commands, you can start creating powerful automation scripts to test your web applications.


Russell Morley

Test Lead | Software Developer In Test | Automation Enthusiast