SeleniumStandaloneDsl
Gem for using Selenium webdriver simply.
Installation
Ensure you already install Firefox:
sudo apt-get install firefox
If you want to run firefox headlessly, install Xvfb:
sudo apt-get install xvfb
Add this line to your application's Gemfile:
gem 'selenium_standalone_dsl'
And then execute:
bundle
Or install it yourself as:
gem install selenium_standalone_dsl
Usage
class YahooSearcher < SeleniumStandaloneDsl::Base
def search_for_wikipedia
visit 'https://www.yahoo.com/'
fill_in 'p', with: 'wikipedia'
# You can declare how to find elements: [class|id|css|xpath]
click 'IconNavSearch', find_by: :class
if has_element? :text, 'Next'
click 'Next'
end
# You can use full jQuery CSS selector using 'search'
puts search('span:contains("results")').inner_text
end
end
config = {
log_path: '/tmp/selenium_standalone_dsl.log',
user_agent: 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 ' +
'(KHTML, like Gecko) Chrome/51.0.2704.84 Safari/537.36',
headless: true,
}
driver = YahooSearcher.new(config)
driver.search_for_wikipedia
# => 141,000,000 results
Development
git clone [email protected]:acro5piano/selenium_standalone_dsl.git
cd selenium_standalone_dsl
bundle install --path vendor/bundle
bundle exec rake install
bundle exec rake spec
To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/acro5piano/selenium_standalone_dsl. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
License
The gem is available as open source under the terms of the MIT License.