1

I have an R code using RSelenium, where for a given website I want the code to click the "get more departures" button. I have seen a similar question, however when I enter the "class" name in the the findelement function the result is that a button with the same class name higher on the page is clicked.

Could someone please help to click the "get more departures" button?

Would greatly appreciate any insight- as I am a beginner and got stuck here for hours!

Here is my current code which works for clicking the "Mars 12" button

library(RSelenium)
library(rvest)

rd <- rsDriver(browser = "firefox", port = 4478L)
ffd <- rd$client

ffd$navigate(paste0("https://www.flightsfrom.com/LAX/departures?durationFrom=21&durationTo=1071&dateMethod=day&dateFrom=2020-03-12&dateTo=2020-03-12",sep=""))

load_btn <- ffd$findElement(using = "css selector", ".button.md-raised.blue-md-button.md-primary.md-button.md-ink-ripple")
load_btn$clickElement()
Roberto
  • 181
  • 8
  • I second this, would also be curious to know if there is a way to click through all "load more" type buttons until no longer available – Peter Alexander Mar 13 '20 at 01:59
  • 1
    Try `findElements` instead. This should return all elements with that class. – R. Schifini Mar 13 '20 at 02:11
  • Thank you for the quick reply. I have tried "findElements" and that line seems to work. However the subsequent command "clickElement" return an error (attempt to apply non-function). Should be using load_btn$clickElement()[2,] or something along those lines to extract the second element identified? Many thanks – Roberto Mar 13 '20 at 02:23

0 Answers0