-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget business objects csv.R
109 lines (78 loc) · 3.35 KB
/
get business objects csv.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
library(RSelenium)
library(magrittr)
library(tidyverse)
library(keyring)
#key_set("idph_username") #set your IDPH web portal username -- only needs to be done once per computer
#key_set("idph_portal") #set your IDPH web portal password -- only needs to be done once per computer
#Set report name
name <- paste0(Sys.Date(), "")
#Load helper functions
devtools::source_url("https://github.com/hsteinberg/ccdph-functions/blob/master/general-use-rselenium-functions.R?raw=TRUE")
devtools::source_url("https://github.com/hsteinberg/ccdph-functions/blob/master/inedss-rselenium-functions.R?raw=TRUE")
#Setting Firefox to avoid download type
firefoxProfile <- makeFirefoxProfile(list(browser.helperApps.neverAsk.saveToDisk = "application/comma-separated-values, text/csv, text/plain, application/zip, application/octet-stream"))
#Open selenium session
remDr <- rsDriver(browser = "firefox", extraCapabilities = firefoxProfile)
#Extract the client for navigation
rD <- remDr[['client']]
#Navigating to log-in page
rD$navigate("https://dph.partner.illinois.gov/my.policy")
#Pause for page to load
Sys.sleep(5)
#Check for cookies error
login_error <- try(rD$findElement("css", "#newSessionDIV > a:nth-child(1)"))
if (class(login_error) != "try-error") {login_error$clickElement()}
#Pause for page to load
Sys.sleep(5)
#Clicking link to access log-in screen
click(".interaction_table_text_cell > a:nth-child(1)")
#Pause for page to load
Sys.sleep(5)
#Enter credentials and log in
enter_text("#input_1", c(key_get("idph_username"), key = "tab", key_get("idph_portal")))
click(value.is("Logon"))
#Pausing execution to give time to log in and load page
Sys.sleep(10)
#Mousing over applications button
rD$findElement(using = "xpath", value = '//*[@id="zz6_RootAspMenu"]/li/ul/li[1]/a/span/span')$mouseMoveToLocation()
#Finding production apps button
rD$findElement(using = "xpath", value = '//*[@id="zz6_RootAspMenu"]/li/ul/li[1]/a')$clickElement()
#Identify production apps present on page
appsTableLinks <- rD$findElements("css", "a.dph-applink")
#Store location of BO link
BOLink <- map_chr(appsTableLinks, function(x) x$getElementText()[[1]]) %>%
grepl("Business Objects", .) %>%
which(. == TRUE)
#Click INEDSS link
appsTableLinks[[BOLink]]$clickElement()
#Pausing execution to give time to load page
Sys.sleep(5)
#Switching focus to BO tab
windows <- rD$getWindowHandles()
rD$switchToWindow(windows[[2]])
#Clicking link to access BO log-in screen
click(".interaction_table_text_cell > a:nth-child(1)")
#Pause for page to load
Sys.sleep(5)
#Enter BO credentials
enter_text("#input_1", c(key_get("idph_username"), key = "tab", key_get("idph_portal")))
ifVisiblethenClick("option[value = \"idph.il\"]")
click(value.is("Logon"))
#Pausing execution to give time to log in and load page
Sys.sleep(60)
#Get into inbox - in nested iframe so need to get into correct frame first
frames_first <- rD$findElements(using = "tag name", "iframe")
rD$switchToFrame(frames_first[[1]])
frames_second <- rD$findElements(using = "tag name", "iframe")
rD$switchToFrame(frames_second[[5]])
#Get titles of unread items in BO inbox
titles <- character(10)
for (i in 1:10) {
titles[i] <- get_text(paste0("#id_", i + 52))
}
#Click desired item
click(paste0("#id_", which(grepl(name, titles)) + 52))
#Pausing execution for 1 minute to give time to download the report
Sys.sleep(60)
#stop server
remDr$server$stop()