Last active
October 11, 2023 06:59
-
-
Save DanyWallace/607db75679a004f289c56505fc7802aa to your computer and use it in GitHub Desktop.
a cheatsheet or example usage of selenium with ruby in windows (works for linux)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "selenium-webdriver" | |
# See the following for newer drivers : https://googlechromelabs.github.io/chrome-for-testing/#stable | |
# ^ https://edgedl.me.gvt1.com/edgedl/chrome/chrome-for-testing/*/win64/chrome-win64.zip | |
# ^ note the '*', and navigate to C:\Users\USERNAME\.cache\selenium\chrome\win64, replace files there | |
# otherwise for older: https://chromedriver.chromium.org/downloads | |
# remember: | |
# https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings | |
options = Selenium::WebDriver::Chrome::Options.new | |
#prefs = { | |
# prompt_for_download: false, | |
# default_directory: "/path/to/dir" | |
#} | |
#options.add_preference(:download, prefs) | |
#options.add_argument("--user-data-dir=/path/to/your/custom/profile") | |
# Selenium::WebDriver.logger.level = :debug | |
driver = Selenium::WebDriver.for :chrome | |
#driver = Selenium::WebDriver.for :remote, desired_capabilities: :chrome, url: "http://myserver:4444/wd/hub" | |
## proxied: | |
#client = Selenium::WebDriver::Remote::Http::Default.new | |
#client.proxy = Selenium::Proxy.new(http: "proxy.org:8080") | |
#driver = Selenium::WebDriver.for :remote, http_client: client | |
# driver.navigate.to "http://google.com" | |
# driver.find_element(:xpath => "//*[@class='checkmark' and contains(text(),'Apple')]") | |
# driver.element.click | |
# driver.element.text | |
# Wait until the element is displayed | |
#wait = Selenium::WebDriver::Wait.new(timeout: 30) | |
#wait.until { element.displayed? } | |
#wait.until { element.displayed == 'text' } | |
# javascript | |
#variable = driver.execute_script("return arguments[0].tagName" , element) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment