Description Usage Arguments Value See Also Examples
View source: R/documentHandling.R
getPageSource
Get the source of the last loaded page.
1 | getPageSource(remDr, ...)
|
remDr |
An object of class "rDriver". A remote driver object see
|
... |
Additonal function arguments - Currently passes the
|
read_html(res$value): An xml document is returned.
The content from the remote webdriver is parsed (see
read_html
) and returned as xml.
Other documentHandling functions: executeAsyncScript
,
executeScript
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 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | ## Not run:
remDr <- remoteDr()
# Get the page source
remDr %>% go("https://www.google.com/ncr") %>%
getPageSource
remDr %>% getTitle()
webElem <- remDr %>% findElement("css", "img#hplogo")
# check if the logo is hidden
remDr %>% executeScript("return document.getElementById('hplogo').hidden;",
args = list())
# [1] FALSE
# hide the logo
remDr %>% executeScript("document.getElementById('hplogo').hidden = true;",
args = list())
# Make the logo visible this time passing a web Element as an argument
remDr %>% executeScript(script = "return arguments[0].hidden = false;",
args = list(webElem))
# Pass arguments
remDr %>% executeScript(script = "return argument[1] + argument[2];"
, args = list(1, 2))
# Return a web Element
remDr %>% executeScript(
script = "return document.getElementById('hplogo');",
args = list())
# ElementId: 0
# Remote Driver:
# Remote Ip Address: http://localhost:4444/wd/hub
# Remote sessionId: 9a83672a-d72b-4873-aa7d-96f7f1f80fa0
# Return a web Element in a more complex object
script <-
"var test ={num:1, str:'a', el:document.getElementById('hplogo')};
return test;"
remDr %>% executeScript(script = script
, args = list())
# $str
# [1] "a"
#
# $num
# [1] 1
#
# $el
# ElementId: 0
# Remote Driver:
# Remote Ip Address: http://localhost:4444/wd/hub
# Remote sessionId: 9a83672a-d72b-4873-aa7d-96f7f1f80fa0
# Run with replace = FALSE
remDr %>% executeScript(script = script
, args = list(), replace = FALSE)
# $str
# [1] "a"
#
# $num
# [1] 1
#
# $el
# $el$ELEMENT
# [1] "0"
remDr %>% setTimeout("script")
asScript <- "cb = arguments[0];setTimeout(function(){cb('DONE');},5000); "
system.time(test1 <- remDr %>% executeAsyncScript(asScript, args = list()))
sScript <- "setTimeout(function(){},5000); return 'DONE';"
system.time(test2 <- remDr %>% executeScript(sScript, args = list()))
remDr %>% deleteSession()
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.