View on GitHub

Relenium

Selenium for R

Download this project as a .zip file Download this project as a tar.gz file

Class firefoxClass. A class to represent Firefox web browser

Description

This class is designed to represent and interact with a Firefox web browser.

Details

The firefox class is implemented as a reference class (see ReferenceClasses for more details). This class is designed to represent and interact with a Firefox web browser.

You can open a new Firefox web browser with firefoxClass$new(), navigate to any web page, web data extraction and find web elements by diferent ways like tag name, text, id, xpath and others.

All methods implemented are explained below. Documentation is based in the original Selinum Java documentation. It is possible to access the methods with TAB completion.

Normally the Firefox binary is assumed to be in the default location for your particular operating system:

A simple firefoxClass example can be found at the end of this file. You can get a more sofisticated one using demo(package = "relenium").

Methods

Navigate and web data extraction

get(url = ""):

Use this method to load a new web page in the current browser window.

getTitle():

Use this method to get the title of the current page, with leading and trailing whitespace stripped, or null if one is not already set.

getCurrentUrl():

Use this method to get a string representing the current URL that the browser is looking at.

getPageSource():

Use this method to get the source of the last loaded page.

printHtml():

Use this method to parse and print the the html code of the last loaded page. It is like getPageSource but it returns the html code in a more readable form.

forward():

Use this method to move a single "item" forward in the browser's history. Does nothing if we are on the latest page viewed.

back():

Use this method to move back a single "item" in the browser's history.

close():

Use this method to close the Firefox browser.

Locating elements

There are diferent methods to find a single element in a page. All the functions from the 'findElement/s' family have the same argument stringName = "". Functions of type 'finElement' return a webElementClass object. Functions of type 'finElements' return a list of webElementClass objects.

findElementByXPath:

Use this method when you know the xpath of an element. With this strategy, the first element matching the xpath will be returned.

findElementByClassName:

Use this method when you know class attribute of an element. With this strategy, the first element with the class attribute value matching the location will be returned.

findElementByCssSelector:

Use this method to find elements via the driver's underlying W3 Selector engine. If the browser does not implement the Selector API, a best effort is made to emulate the API.

findElementById:

Use this method when you know id attribute of an element. With this strategy, the first element with the id attribute value matching the location will be returned.

findElementByName:

Use this method when you know the name attribute of an element. With this strategy, the first element with the name attribute value matching the location will be returned.

findElementByLinkText:

Use this method when you know text of an element. With this strategy, the first element matching the exact text will be returned.

findElementByPartialLinkText:

Use this method when you know text of an element. With this strategy, the first element matching the partial text will be returned.

findElementByTagName:

Use this method when you know the tag name of an element. With this strategy, the first element matching the tag name will be returned.

To find multiple elements use the following methods in the same way as the previous ones. Note that these methods will return a list.

See Also

ReferenceClasses, relenium-package, webElementClass

Examples


  ## Not run: 
##D     require(relenium)
##D 
##D     firefox <- firefoxClass$new()
##D     firefox$get("https://github.com/LluisRamon/relenium")
##D     firefox$getTitle()
##D     firefox$close()
##D   
## End(Not run)


Package relenium version 0.3.0 Index