0

My code below sends a request to a Japanese geolocation website, and gets a new page, but I can't get RSelenium to locate and click on the link.

library(XML)
library(RSelenium)

remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "firefox"
)

remDr$open()
remDr$navigate("https://maps.gsi.go.jp")
remDr$screenshot(display = TRUE)
remDr$getCurrentUrl()

webElem <- remDr$findElement(using = "id", value = "query")
webElem$getElementAttribute("id")
webElem$highlightElement()
webElem$sendKeysToElement(list("茨城県行方郡玉造町","\uE007"))
remDr$screenshot(display = TRUE)

I want to click on the node below and get the URL from the new page, but none of my attempts with remDr$findElement are working. Am I missing something obvious?

<a href="javascript:void(0);" style="padding-left: 32px; background: url(&quot;image/mapicon/search_result.png&quot;) 0px 50% no-repeat;"><div class="title">茨城県行方郡</div><div class="muni">茨城県行方市</div></a>

Dominik S. Meier
  • 3,463
  • 1
  • 7
  • 17
Mark R
  • 588
  • 4
  • 18

2 Answers2

0

Like this?

link <- remDr$findElement(using = "css selector", value = ".muni")
link$highlightElement()
link$clickElement()
remDr$getCurrentUrl()
Dominik S. Meier
  • 3,463
  • 1
  • 7
  • 17
  • 1
    This worked once, but now I have identical Docker trouble on two separate machines. I'll get back to you once I resolve that! – Mark R Jun 04 '20 at 21:15
0

With XPath :

remDr$navigate("https://maps.gsi.go.jp")
webElem <- remDr$findElement(using = "xpath","//input[@id='query']")
webElem$clickElement()
webElem$sendKeysToElement(list("茨城県行方郡玉造町", key = "enter"))

webElem2 <- remDr$findElement(using = "xpath","//div[@class='searchresultdialog_ul_frame']//a")
webElem2$clickElement()

If you get errors, use while/Trycatch combo (credits to @Victor Burnett) to wait the presence of the element.

E.Wiest
  • 5,122
  • 2
  • 4
  • 11