0

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,,

  • The link you provided is broken (I get a popup with this message when I click it: "Message: (TypeError): Cannot read property 'j' of undefined"), also I think you have a typo in the brackets, not sure what you were trying to say there, try editing it. – T.G. Apr 05 '21 at 07:00
  • This is strange... the link works when click on it just fine. The brackets should read... (how to key in username and password) when authentication window pops up when scrapping with Rselenium. I am trying to programmatically access and download some satellite based vegetation products from : https://land.copernicus.vgt.vito.be – Reagan Okoth Apr 06 '21 at 18:37
  • You can use shorter `xpath` `//*[@id="login"]` and `//*[@id="password"]` for username and password. – Nad Pat Dec 11 '21 at 10:23

1 Answers1

0

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()
BDuff
  • 46
  • 3