View on GitHub

Relenium

Selenium for R

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

Class webElementClass. A class to represent a web element

Description

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

Details

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

It represents an HTML element. Generally, all interesting operations to do with interacting with a page will be performed through this interface.

You get a webElementClass from firefoxClass find methods or from other webElementClass. With this class you can navigate, select, web data extraction and find web elements.

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.

An example of webElementClass can be found using demo(package = "relenium").

Fields

keys:

This is a list of the available keys that can be used in the 'sendKeys' method. They refer to keys of the keyboard.

Methods

Navigate and web data extraction

clear():

If this element is a text entry element, this will clear the value.

click():

Click this element.

getAllAttributes():

All the attributes from the selected tag.

getAttribute(stringName = ""):

Get the value of a the given attribute of the element.

getCssValue(stringName = ""):

Get the value of a given CSS property.

getHtml(tagLine = TRUE):

Get the inner html code of this element. If tagLine = TRUE, the code includes the tag line code.

getId():

Get the id of this element. Returns a character.

getSize():

Returns a vector with the height and the width (in this order) of the rendered element.

getTagName():

Get the tag name of this element.

getText():

Get the visible text

printHtml(tagLine = TRUE):

Parse and print the inner html code of this element. It is like getHtml but it returns the html code in a more readable form. If tagLine = TRUE, the code includes the tag line code.

isDisplayed():

Is this element displayed or not?

isEnabled():

Is the element currently enabled or not? This will generally return true for everything but disabled input elements

isSelected():

Determine whether or not this element is selected or not. This operation only applies to input elements such as checkboxes, options in a select and radio buttons. It returns True if the element is currently selected or checked, false otherwise.

sendKeys(text = NULL, keys = ""):

Use this method to simulate typing into an element, which may set its value. The argument text should be a character.

submit():

If this current element is a form, or an element within a form, then this will be submitted to the remote server.

Select methods

These apply to web elements with tag 'select'.

isMultiple():

Whether this select element support selecting multiple options at the same time? This is done by checking the value of the "multiple" attribute.

getOptions():

Use this method to get all options belonging to this select tag. Returns a list of webElementClass objects.

getAllSelectedOptions:

All selected options belonging to this select tag. Returns a list of webElementClass objects.

getFirstSelectedOption():

he first selected option in this select tag (or the currently selected option in a normal select. Returns a webElementClass object.)

selectByVisibleText(stringName = ""):

Select all options that display text matching the argument. That is, when given "Bar" this would select an option like: <option value="foo">Bar</option>

selectByIndex(ind = 1):

Select the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting.

selectByValue(stringName = ""):

Select all options that have a value matching the argument. That is, when given "foo" this would select an option like: <option value="foo">Bar</option>

deselectAll():

Clear all selected entries. This is only valid when the SELECT supports multiple selections.

deselectByIndex(ind = 1):

Deselect the option at the given index. This is done by examing the "index" attribute of an element, and not merely by counting.

deselectByValue(stringName = ""):

Deselect all options that have a value matching the argument. That is, when given "foo" this would deselect an option like: <option value="foo">Bar</option>

deselectByVisibleText(stringName = ""):

Deselect all options that display text matching the argument. That is, when given "Bar" this would deselect an option like: <option value="foo">Bar</option>

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, firefoxClass


Package relenium version 0.3.0 Index