0

I have a code in R where I am using Selenium to get URL from Google Maps. But it doesn't work:

for (i in 1:dim(Coord_t)[1])
{
  remDr$navigate("https://www.google.ro/maps") # navigates to webpage
  
  # select CNP field
  option <- remDr$findElement(using='xpath', "//*[@id='searchboxinput']")
  option$highlightElement()
  option$clickElement()
  option$sendKeysToElement(list(Coord_t$Conc[i]))
  
  #press key
  webElem <- remDr$findElement(using = 'css', "#searchbox-searchbutton")
  webElem$highlightElement()
  webElem$clickElement()

  remDr$setTimeout(type = "page load", milliseconds = 10000)

  Coord_t$Url[i] = remDr$getCurrentUrl()
  
}

Coord$Conc[i] it is a simple name of a restaurant, hotel etc. I get the first URL and after I get only: "https://www.google.ro/maps". I tried also with: webElem$getCurrentUrl() and option$getCurrentUrl() and it doesn't work.

I just can't figure it out what is wrong here.

Thank you!

EDIT: I found that the problem is with "page load". It seems that I have to set a timeout to wait the page load. I did this with setTimeout but it doesn't work.

Mary Nastase
  • 111
  • 11

0 Answers0