-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathselenium-examples.r
56 lines (34 loc) · 1.75 KB
/
selenium-examples.r
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
library('RSelenium')
user <- "mgalka" # Your Sauce Labs Username
pass <- "4c080716-a10a-414f-894c-e108178b4de1" # Your Sauce Labs password
port <- 80
ip <- paste0(user, ':', pass, "@ondemand.saucelabs.com")
rdBrowser <- "chrome"
version <- "33"
platform <- "Windows 10"
extraCapabilities <- list(name = "RSelenium", username = user
, accessKey = pass, tags = list("RSelenium-vignette", "OS/Browsers-vignette"))
remDr <- remoteDriver$new(remoteServerAddr = ip, port = port, browserName = rdBrowser
, version = version, platform = platform
, extraCapabilities = extraCapabilities)
remDr$open()
remDr$navigate("https://blueshift.io/selectors.html")
# #programming-languages > li.item.unordered-item.item3
#//*[@id="programming-languages"]/li[3]
#****SELECT BY TAG****
allListItems <- remDr$findElements("tag name","li")
unlist(lapply(allListItems, function(x){x$getElementText()}))
#****SELECT BY CLASS****
firstItems <- remDr$findElements("class name", "item1")
unlist(lapply(firstItems, function(x){x$getElementText()}))
#****SELECT BY ID****
fruitList <- remDr$findElement("id", "fruits")
fruitList$getElementText()
#****SELECT BY CSS SELECTOR****
# Find the element with an id of "programming-languages". From its children, select the first one with a class name of "item2".
cssExample <- remDr$findElement("css selector", "#programming-languages > li.item.unordered-item.item3")
cssExample$getElementText()
#****SELECT BY XPATH****
# Find the element with an id of "fruits", From its children, select the first "li" element.
xpathExample <- remDr$findElement(using = "xpath","//*[@id='fruits']/li[1]")
xpathExample$getElementText()