I have a Ruby application using Selenium Webdriver and Nokogiri. I want to select a class, and then for each div corresponding to this class, I want to perform an action based on the contents of the div.
For example, I am parsing the following page:
https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8
This is a search results page, and I'm looking for the first result with the word "Adoption" in the description. Therefore, the bot should look for divs with className: "result"
, because everyone checks to see if their .description
div contains the word "acceptance", and if so, click on the .link
div. In other words, if .description
does not include this word, then the bot proceeds to the next .result
.
This is what I still have that just clicks on the first result:
require "selenium-webdriver" require "nokogiri" driver = Selenium::WebDriver.for :chrome driver.navigate.to "https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=puppies" driver.find_element(:class, "link").click
source share