Sie sind auf Seite 1von 6

1.

2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
Table of Cohtehts
Local Cohfiguratioh
Cloud Cohfiguratioh
Headless Cohfiguratioh
Commoh Actiohs
Locators
Cookies
Dropdowh Lists
Exceptioh Hahdlihg
Iile Trahsfers
Irames
Hovers
|avaScript
Iey Presses
Multiple Wihdows
Screehshots
Waitihg
1.
2.
3.
1.
2.
3.
Local Cohfiguratioh
Chrome
Dowhload the latest ChromeDriver bihary from here
Add it to your path, or tell Selehium where to fihd it
Create ah ihstahce of Chrome
require 'selenium-webdriver'
Selenium::WebDriver::Chrome::Service.executable_path = './chromedriver'
driver = Selenium::WebDriver.for :chrome
Ior more ihfo:
the Selehium wiki page for ChromeDriver
the official user documehtatioh
Iirefox
Available out of the box.
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
Ior more ihfo:
the Selehium wiki page for IirefoxDriver
Ihterhet Explorer
Chly available oh Microsoft Wihdows.
Dowhload the latest IEDriverServer from here
Add the dowhloaded file locatioh to your path
Create ah ihstahce of Ihterhet Explorer
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :internet_explorer
Ior more ihfo:
1.
2.
3.
the Selehium wiki page for IhterhetExplorerDriver
Cpera
Chly works for versioh 12.16 or earlier. Ior hewer versiohs of Cpera, test usihg Chrome (sihce it
uses the same back-ehd).
Dowhload the latest Selehium Stahdalohe Server from here
Create ah ehvirohmeht variable poihtihg to the server file
Create ah ihstahce of Cpera
require 'selenium-webdriver'
ENV['SELENIUM_SERVER_JAR'] = './selenium-server-standalone.jar'
driver = Selenium::WebDriver.for :opera
driver.get 'http://www.google.com'
driver.quit
Ior more ihfo:
The Selehium wiki page for CperaDriver
Safari
Available out of the box as of versioh 2.21 of Selehium.
require 'selenium-webdriver'
driver = Selenium::WebDriver.for :safari
Ior more ihfo:
the Selehium wiki page for SafariDriver
Commoh Actiohs
visit a page
driver.get 'url'
# e.g., driver.get 'http://the-internet.herokuapp.com'
Iihd ah elemeht
# just one, the first Selenium finds
driver.find_element(locator)
# all instances of the element on the page
driver.find_elements(locator)
# returns an Array
Work with a fouhd elemeht
# Chain actions together
driver.find_element(locator).click
# Store the element
element = driver.find_element(locator)
element.click
Work with a collectioh of fouhd elemehts
collection = driver.find_elements(locator)
# by name
collection.first.click
collection.last.click
# by index
collection[0].click
collection[-1].click
Perform ah actioh
element.click
element.submit # submits a form
element.clear # clearing an input field of its text
element.send_keys # typing into an input field
Ask a questioh
element.displayed? # is it visible?
element.enabled? # can it be selected?
element.selected? # is it selected?
Retrieve ihformatioh
# by attribute name
element.attribute('href')
# directly from an element
element.text
Ior more ihfo:
the Elemeht API documehtatioh
the Elemeht API documehtatioh attribute

Das könnte Ihnen auch gefallen