Search code examples
rchromote

How do I open a new tab or window in selenider in R?


I am running a chromote session via selenider in R and need to open a new tab or window. Is this possible?

library(selenider)

session <- selenider_session(
  "chromote",
  options = chromote_options(headless = FALSE),
  timeout = 10
)

Solution

  • It's possible, but it is not supported. That means, selenider is made to operate only within one window at a time. But, we can fake a click on an element to open a new tab.

    library(selenider)
    
    session <- selenider_session( # open window instead
      "selenium", browser = "chrome"
    )
    
    open_url("https://www.r-project.org/")
    find_element(session, css = "a[target='_blank']") |> 
      elem_click()
    

    Instead, just work with multiple sessions like this. Where each session is opened in a separate window.

    library(selenider)
    
    s1 <- selenider_session( # open window instead
      "selenium", browser = "chrome"
    )
    
    open_url("https://www.r-project.org/", session = s1 )
    
    s2 <- selenider_session( # open window instead
      "selenium", browser = "chrome"
    )
    
    open_url("https://www.google.com/", session = s2 )