selenium-webdriver is a gem. Let’s see what it is.
I install it by
gem install selenium-webdriver
and I need a browser driver
brew cask install chromedriver
irb # run Interactive Ruby Shell
driver = Selenium::WebDriver.for :chrome
chrome is open, and I can operate it by the variable named driver, I use driver to open a page
driver.get "https://www.baidu.com"
the input of Baidu is
<input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
I send “ruby” to the input
driver.find_element(:id => "kw").send_keys("ruby")
click to search
<input type="submit" id="su" value="百度一下" class="bg s_btn">
driver.find_element(:id => "su").click
go back
driver.navigate.back
resize the browser
driver.manage.window.resize_to(400, 300)
close it
driver.close