Search for an element on the page

Share:

Description

findElement Search for an element on the page, starting from the document root. The located element will be returned as an object of "wElement" class

Usage

1
2
findElement(remDr, using = c("xpath", "css selector", "id", "name",
  "tag name", "class name", "link text", "partial link text"), value, ...)

Arguments

remDr

An object of class "rDriver". A remote driver object see remoteDr.

using

Locator scheme to use to search the element, available schemes: "class name", "css selector", "id", "name", "link text", "partial link text", "tag name", "xpath" . Defaults to 'xpath'. Partial string matching is accepted.

value

The search target. See examples.

...

Additonal function arguments - Currently passes the retry argument.

Details

Details of possible locator schemes

"class name" :

Returns an element whose class name contains the search value; compound class names are not permitted.

"css selector" :

Returns an element matching a CSS selector.

"id" :

Returns an element whose ID attribute matches the search value.

"name" :

Returns an element whose NAME attribute matches the search value.

"link text" :

Returns an anchor element whose visible text matches the search value.

"partial link text" :

Returns an anchor element whose visible text partially matches the search value.

"tag name" :

Returns an element whose tag name matches the search value.

"xpath" :

Returns an element matching an XPath expression.

Value

invisible(wbElement(res$value, remDr)): An object of class "wElement" is invisibly returned. A webElement object see wbElement. This allows for chaining from this function to other functions that take such an object as an argument. See examples for further details.

See Also

Other elementRetrieval functions: findElementFromElement, findElementsFromElement, findElements, getActiveElement

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
## Not run: 
  remDr <- remoteDr()
  remDr %>% go("http://www.google.com/ncr")

  # find the search form query box and search for "R project"
  webElem <- remDr %>% findElement("name", "q") %>%
    elementSendKeys("R project", key = "enter")
  # click the first link hopefully should be www.r-project.org
  remDr %>% findElement("css", "h3.r a") %>% elementClick

  # get the navigation div
  navElem <- remDr %>% findElement("css", "div[role='navigation']")

  # find all the links in this div
  navLinks <- navElem %>% findElementsFromElement("css", "a")

  # check the links
  nLinks <- sapply(navLinks, function(x) x %>% getElementText)

  # compare with all links
  allLinks <- remDr %>% findElements("css", "a")
  aLinks <- sapply(allLinks, function(x) x %>% getElementText)

  # show the effect of searching for elements from element
  aLinks %in% nLinks

  remDr %>% deleteSession

## End(Not run)

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.