Learn R Programming

seleniumPipes

CRAN versionTravis build statusSauceTestsCoverage

Selenium test status

A lightweight implementation of w3c webdriver specification

Introduction

seleniumPipes is a lightweight implementation of the w3c webdriver specification. It has been built utilising xml2, httr and magrittr so provides an alternative for users who are familiar with piping.

Install

To install seleniumPipes from CRAN

install.packages("seleniumPipes")

To install the current developement version of seleniumPipes run:

devtools::install_github("johndharrison/seleniumPipes")

Getting started

The easiest way to start is to look at the Basic operations vignette:

Failing this a few basic examples are presented below:

Get started using seleniumPipes you can look at the following example

library(seleniumPipes)
library(RSelenium) # start a server with utility function
selServ <- RSelenium::startServer()
remDr <- remoteDr()
remDr %>% go(url = "http://www.google.com")
remDr %>% go(url = "http://www.bbc.com")
remDr %>% back()
remDr %>% forward()
remDr %>% refresh()
remDr %>% go("https://cloud.r-project.org/") %>% getPageSource()
# {xml_document}
# <html>
# [1] <head>\n<title>The Comprehensive R Archive Network</title>\n<meta content="text/html; charset=u ...
# [2] <frameset style="border: none;" cols="1*, 4*">\n<frameset rows="120, 1*">\n<frame frameborder=" ...

remDr %>% getPageSource() %>% xml_find_all("//frame") %>% xml_attr("name")
 
# [1] "logo"     "contents" "banner"  

remDr %>% deleteSession()
selServ$stop()

Piping

Piping in seleniumPipes is achieved using the pipe operator from magrittr %>%`:

remDr %>% go("http://www.google.com/ncr") %>% 
  findElement("name", "q") %>% 
  elementSendKeys("R project", key = "enter")
  

Functions relating to the remote driver which would not be expected to return data can be expected to return the remote driver. Functions relating to a web element which would not be expected to return data can be expected to return the web element. This allows chaining of commands as shown above.

Further examples are available on install in the examples directory.

Builtin retry of Endpoints

remDr <- remoteDr()
webElem <- remDr %>% go("http://www.google.com/ncr") %>% 
  findElement("name", "q")

# change the name of q with an 8 second delay
myscript <- "var myElem = arguments[0]; window.setTimeout(function(){
 myElem.setAttribute('name','funkyname');
}, 8000);"
remDr %>% executeScript(myscript, args = list(webElem))

newWebElem <- remDr %>% findElement("name", "funkyname")

# > newWebElem <- remDr %>% findElement("name", "funkyname")
# 
# Calling  findElement  - Try no:  1  of  3 
# 
# Calling  findElement  - Try no:  2  of  3 

newWebElem %>% getElementAttribute("name")

Copy Link

Version

Install

install.packages('seleniumPipes')

Monthly Downloads

398

Version

0.3.7

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

John Harrison

Last Published

October 1st, 2016

Functions in seleniumPipes (0.3.7)

deleteCookie

Delete a given cookie.
back

Navigate backwards
acceptAlert

Accept alert
addCookie

Add a specific cookie.
checkResponse

Check the response from remote server
deleteSession

Delete the session.
dismissAlert

Dismiss Alert
closeWindow

Close the current window.
acceptAlertOld

Accept alert
deleteAllCookies

Delete all the cookies.
executeAsyncScriptOld

executeAsyncScriptOld
errorResponse

Return the response from remote webdriver
dismissAlertOld

Dismiss Alert
executeScript

Execute JavaScript on browser.
elementClick

Click on an element.
errorContent

Returns the content from remote webdriver
elementSendKeys

Send a sequence of key strokes to an element.
executeAsyncScript

Execute JavaScript asynchronously on browser.
executeScriptOld

Execute JavaScript asynchronously on browser.
elementClear

Clear an elements text value.
getAllCookies

Get all current domain cookies
getActiveElement

Get the element on the page that currently has focus.
getAlertTextOld

Get alert text
findElementsFromElement

Search for multiple elements on the page, starting from another element.
findElements

Search for multiple elements on the page
findElement

Search for an element on the page
getAlertText

Get alert text
findElementFromElement

Search for an element on the page, starting from another element
forward

Navigate forwards
fullscreenWindow

Make current window full-screen
getPageSource

Get source of last page.
getNamedCookie

Get a named cookie
getTitle

Get the current page title.
getElementCssValue

Query the value of an element's computed CSS property.
getCurrentUrl

Retrieve the URL of the current page.
getElementTagName

Query for an element's tag name.
getElementText

Returns the visible text for the element.
getElementAttribute

Get the value of an element's attribute.
getElementRect

Return the dimensions and coordinates of an element
getElementProperty

Query the value of an elements property.
getWindowPosition

Get current window position
getWindowPositionOld

Get window position
isElementEnabled

Determine if an element is currently enabled.
getWindowHandle

get current window handle
getWindowHandlesOld

Get all window handles.
go

Navigate to a new URL.
getWindowHandles

Get all window handles.
getWindowHandleOld

Retrieve the current window handle.
getWindowSize

getWindowSize
getWindowSizeOld

Get window size
performActions

Not currently implemented
queryDriver

Send a query to remote Driver.
refresh

Refresh the current page.
releasingActions

Not currently implemented
maximizeWindowOld

Maximize the current window.
newSession

Create a new session.
remoteDr

Create a remote driver
retry

Documetation of retry argument
sendAlertText

Send text to alert
sendAlertTextOld

Send text to alert
wbElement

Create a Web Element
isElementSelected

Determine if an element is currently selected.
maximizeWindow

Maximize the current window.
setWindowPositionOld

Change the position of the specified window.
setWindowSizeOld

Change the size of the specified window.
setWindowSize

Change the size of the current window.
takeElementScreenshot

takeElementScreenshot
switchToFrame

Change focus to another frame on the page.
takeScreenshot

takeScreenshot
setTimeout

Configure the amount of time that a particular type of operation can execute
setWindowPosition

Change the position of the current window.
seleniumPipes

Implements the W3C webdriver specification.
selKeys

Selenium key mappings
switchToParentFrame

Change focus to the parent context.
switchToWindow

Change focus to another window.