selenium-chrome.cr

A handy and thin wrapper for `selenium-webdriver-crystal`

selenium-chrome.cr Build Status

A handy and thin wrapper for selenium-webdriver-crystal.

  • crystal: 0.32.0

Component

Prepare Server

The simplest way is

docker run -d -p 4444:4444 selenium/standalone-chrome:3.11.0

Usage

require "selenium-chrome"

session = Selenium::Chrome.new
session.open "https://github.com/maiha/selenium-chrome.cr"

session.find(css: "article>h1").text # => "selenium-chrome.cr"
session.find(css: "xxx")             # raises Selenium::WebElement::NotFound
session.find?(css: "xxx")            # => nil

session.close

async downloader

bytes = session.download(timeout: 60.seconds, interval: 3.seconds) {
  session.find(css: "a>img[name='csv']").click
}
  • When no timeout parameter is given, Setting#download_timeout is used.
  • When no interval parameter is given, Setting#download_interval is used.

sync finder

find! waits until it will appear. This is useful after a page transition or after the element has changed dynamically.

session.find("css:form").submit
session.find!("id:welcome")

API (Session)

method args return value description
close nil closes and deletes this session
css *args Array(WebElement) shortcut for find_elements(:css, *args)
download ext=nil, &block Bytes yields block and returns bytes of downloaded file
id *args WebElement shortcut for find(:id, *args)
fill target, value, parent=nil WebElement replace attribute:value
fill! target, value, parent=nil WebElement works as fill, then waits until value changed
find id=nil, css=nil, parent=nil WebElement call find_element, or raises ArgumentError
find? id=nil, css=nil, parent=nil WebElement? works as find, or returns nil
find! id=nil, css=nil, parent=nil WebElement works as find, then waits until it will appears
open url, strict=false nil visits url, then waits until url changed when strict
select id=nil, css=nil, parent=nil WebElement find and select
select? id=nil, css=nil, parent=nil WebElement? works as select, or returns nil
select! id=nil, css=nil, parent=nil WebElement works as select and esnures it is selected
wait &condition nil waits until the condition becomes true

Installation

Add this to your application's shard.yml:

dependencies:
  selenium-chrome:
    github: maiha/selenium-chrome.cr
    version: 1.6.0

Test

make test

Contributing

  1. Fork it ( https://github.com/maiha/selenium-chrome.cr/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • maiha maiha - creator, maintainer
Repository

selenium-chrome.cr

Owner
Statistic
  • 5
  • 0
  • 1
  • 0
  • 2
  • over 1 year ago
  • March 21, 2018
License

MIT License

Links
Synced at

Thu, 16 May 2024 11:53:24 GMT

Languages