Handling pop-up Authentication windows in Rselenium

119 views Asked by At

Does anyone in this community have any idea how handle (how key in username and password) in pop up window when web-scraping with RSelenium? I am trying to log into the following-data portal and automate bulk download. webpage: https://land.copernicus.vgt.vito.be/PDF/portal/Application.html#Browse;Root=512260;Collection=1000084;Time=NORMAL,NORMAL,-1,,,-1,,

1

There are 1 answers

1
BDuff On

Oftentimes, I'll copy the xpath from inspecting the webpage and use that to find elements - as I've done here:

library(RSelenium)
library(netstat)

rD <- rsDriver(port = free_port(), browser = 'chrome', 
               chromever = "96.0.4664.45",  
               verbose = F)

remDr <- rD[["client"]]

# navigate - I used the url from your comment 
remDr$navigate("https://land.copernicus.vgt.vito.be/PDF/portal/Application.html#Home")

# find the login element
l <- remDr$findElement(using = "id", "login")
# there it is
l$highlightElement(); l$clickElement() # pops up the box to enter credentials 
  

# find the username
l1 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[1]/td[2]/input")
# there it is 
l1$highlightElement()
# sendkeys for username
l1$sendKeysToElement(list("username")) # replace with your username 

# find the password
l2 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[2]/td[2]/input")
# there it is 
l2$highlightElement()
# sendkeys to password
l2$sendKeysToElement(list("password"))

# login 
l3 <- remDr$findElement(using = "xpath", "/html/body/div[13]/div/table/tbody/tr[2]/td[2]/div/div/form/table/tbody/tr[5]/td/button[1]")
# there it is
l3$highlightElement(); l3$clickElement()