Search code examples
web-scrapingrselenium

Accept cookies on a webpage via RSelenium


I would like to "accept cookies" on Tripadvisor using RSelenium.

I managed to do so on Yahoo Finance.

library('RSelenium')
rD <- rsDriver(port = 4836L, browser = c("firefox")) 
remDr <- rD[["client"]]
remDr$navigate("https://finance.yahoo.com/quote/AAPL/news?p=AAPL")
webElems <- remDr$findElements(using = "xpath", "//button[starts-with(@class, 'btn primary')]") 
unlist(lapply(webElems, function(x) {x$getElementText()}))
webElems[[1]]$clickElement()

Can someone find the element on Tripadvisor?

library('RSelenium')
rD <- rsDriver(port = 4836L, browser = c("firefox")) 
remDr <- rD[["client"]]
remDr$navigate("https://www.tripadvisor.de/Attraction_Review-g187323-d23632357-Reviews-Berlin_Global-Berlin.html")

Solution

  • This worked for me, but I could only test it in chrome. Hope it works for you as well

    driver <- rsDriver(browser = c("chrome"), chromever="104.0.5112.79")
    rd <- driver[["client"]]
    rd$navigate("https://www.tripadvisor.de/Attraction_Review-g187323-d23632357-Reviews-Berlin_Global-Berlin.html")
    button <- rd$findElement(using = "id", "onetrust-accept-btn-handler")
    button$clickElement()