create a simple automation script in Ruby,
create a simple automation script in Ruby, you can use the Watir or Selenium WebDriver libraries
To create a simple automation script in Ruby, you can use the Watir or Selenium WebDriver libraries, which allow you to automate interactions with web browsers. In this example, we'll use Watir to automate a web browser to perform a basic task: opening a website and searching for a term on a search engine.
First, you'll need to install the Watir gem. If you haven't installed it yet, use the following command:
gem install watir
Now, you can create a simple automation script in Ruby:
# Start a new browser instance
browser = Watir::Browser.new
# Navigate to a website (e.g., Google)
# Find the search input field and enter a search term
search_input = browser.text_field(name: 'q')
search_term = 'Ruby programming'
# Submit the search
# Wait for a few seconds (you can adjust the time as needed)
# Take a screenshot of the search results page
# Close the browser
In this script:
1. We require the 'watir' gem to use Watir for browser automation.
2. We create a new browser instance and navigate to the Google website.
3. We find the search input field and enter a search term (in this case, 'Ruby programming').
4. We submit the search by simulating the Enter key.
5. We wait for a few seconds (you can adjust the time as needed) to let the search results load.
6. We take a screenshot of the search results page and save it as 'search_results.png' in the current directory.
7. Finally, we close the browser.
You can modify this script to automate other web interactions, such as form submissions, button clicks, or data extraction. Watir and Selenium WebDriver are powerful tools for web automation and can be used for a wide range of tasks.