Home > Net >  Date Picking with RSelenium and Calendar Format
Date Picking with RSelenium and Calendar Format

Time:11-16

I would like to scrape ticket prices with RSelenium. Is it possible to put in keys in Calender-Date Format (see image attached). The element on the website looks like this:

"<span hljs-operator">-day today selected" aria-label="November 12, 2021" aria-current="date" tabindex="-1">12</span>"

The code I used so far:

# go to rail service website 
remDr$navigate("https://www.bahn.de")
# accept cookies
webElems <- remDr$findElements(using = "xpath", "//button[starts- with(@class, 'btn js-accept-all-cookies')]")
unlist(lapply(webElems, function(x) {x$getElementText()}))
webElems[[1]]$clickElement() 
Sys.sleep(10) # wait for page loading

# Fill out forms
from <- "Berlin Hbf"
to <- "Köln Hbf"
day <- "14.11.2021"
time <- "16:00"

remDr$findElement(using = "id", value = "js-auskunft-autocomplete-from")$sendKeysToElement(list(from))
remDr$findElement(using = "id", value = "js-auskunft-autocomplete-to")$sendKeysToElement(list(to))

And from here on I am lost, on the day picking and also on the time.

Flatpickr Date Calendar

CodePudding user response:

Try something like this:

library(RSelenium)
remDr <- remoteDriver(
  remoteServerAddr = "localhost",
  port = 4445L,
  browserName = "firefox"
)
remDr$open()
remDr$navigate("/foo.html")
remDr$navigate("http://www.example.com") # your url
remDr$findElements(using = 'xpath', "//span[@aria-label='November 12, 2021']")[[1]]$clickElement()
  • Related