I would like to click on a specific element of a custom HTML widget at regular intervals.
I have a minimal working example below. The generated widget is from Airbnb. I would like to click the "Next" button every few seconds to scroll through the images. The button's class is "_1rftspj9" (the only button in the app with such a class), which is what I'm trying to use in the custom js script to select it. I'm a javascript novice, so forgive me if I'm missing something obvious.
library(shiny)
ui <- fluidPage(tags$script("
var but = document.querySelector(\"[class='_1rftspj9']\");
setInterval(function () {but.click();},3000);"),
sidebarLayout(
sidebarPanel(),
mainPanel(
shiny::htmlOutput(outputId = "airbnbListing")
)
)
)
server <- function(input, output) {
output$airbnbListing <- renderUI({
HTML(
'<div class="airbnb-embed-frame" data-id="48429200" data-view="home" style="width:1800px;height:1200px;margin:auto"><a href="https://www.airbnb.com/rooms/48429200?check_in=2022-11-28&check_out=2022-12-05&guests=1&adults=1&s=66&source=embed_widget">View On Airbnb</a><a href="https://www.airbnb.com/rooms/48429200?check_in=2022-11-28&check_out=2022-12-05&guests=1&adults=1&s=66&source=embed_widget" rel="nofollow">Beautifully Decorated, Comfortable, Beachfront 3 Bedroom House on Gulf Beach</a><script async="" src="https://www.airbnb.com/embeddable/airbnb_jssdk"></script></div>'
)
})
}
shinyApp(ui = ui, server = server)