ropensci / RSelenium

An R client for Selenium Remote WebDriver
https://docs.ropensci.org/RSelenium
343 stars 81 forks source link

Can't switchToWindow() #205

Closed gioferreira closed 5 years ago

gioferreira commented 5 years ago

Operating System

MacOS Mojave 10.14.5

Selenium Server version (selenium-server-standalone-3.0.1.jar etc.)

rD$server$log() $stderr [1] "09:10:10.983 INFO [GridLauncherV3.parse] - Selenium server version: 4.0.0-alpha-1, revision: d1d3728cae"

Browser version (firefox 50.1.0, chrome 54.0.2840.100 (64-bit) etc.)$browserName

[1] "chrome" $browserVersion [1] "75.0.3770.66"

Other driver version (chromedriver 2.27, geckodriver v0.11.1, iedriver x64_3.0.0, PhantomJS 2.1.1 etc.)

$chrome $chrome$chromedriverVersion [1] "75.0.3770.8 (681f24ea911fe754973dda2fdc6d2a2e159dd300-refs/branch-heads/3770@{#40})"

Expected behaviour

Use switchToWindow to control a newly created window.

Actual behaviour

Can't switchToWindow. Browser stays on the first window created.

Steps to reproduce the behaviour

library(RSelenium)

rD <- rsDriver(verbose = FALSE)
remDr <- rD$client

link <- "http://www.google.com"

mainWindow <- remDr$getCurrentWindowHandle()
print(mainWindow)

[[1]] [1] "CDwindow-540282B8A084A5DF736292212E896588"

script <- paste0('window.open("', link, '", "windowName", "height=768,width=1024");')
remDr$executeScript(script)

currentWindow <- remDr$getCurrentWindowHandle()
allWindows <- remDr$getWindowHandles()
print(allWindows)

[[1]] [1] "CDwindow-540282B8A084A5DF736292212E896588"

[[2]] [1] "CDwindow-379043292526A4B38A6D1F486E77B611"

print(currentWindow) [[1]] [1] "CDwindow-540282B8A084A5DF736292212E896588"

First odd thing: currentWindow == mainWindow (which was captured before creating current window). Trying to switch to allWindows[[2]] which is different from currentWindow

remDr$switchToWindow(allWindows[[2]])
remDr$getCurrentWindowHandle() 

[[1]] [1] "CDwindow-540282B8A084A5DF736292212E896588"

So, no matter what I do I always stay on the first window created. I was wondering if maybe it has to do with the way I create a new window or something related to the most recent chrome driver.

juyeongkim commented 5 years ago

You might be right about this issue due to the most recent chrome driver. Are you using the chrome beta? The current release is v74. I have v74, and switching windows works.

Install the release version of chrome and use the corresponding chrome driver and try again:

List available chrome drivers:

> binman::list_versions("chromedriver")
$mac64
 [1] "2.43"          "2.46"          "70.0.3538.16"  "70.0.3538.67"  "71.0.3578.137"
 [6] "71.0.3578.30"  "72.0.3626.69"  "73.0.3683.20"  "73.0.3683.68"  "74.0.3729.6"  
[11] "75.0.3770.8"  

I have v74 chrome browser, so I'm gonna use "74.0.3729.6" version of chrome driver:

rD <- RSelenium::rsDriver(chromever = "74.0.3729.6")
gioferreira commented 5 years ago

I installed chrome beta 75 because the default driver was set to 75 and I didn't know how to change that. I'll try going back to 74. Thanks!

juyeongkim commented 5 years ago

Gotcha. Yeah I noticed that sometimes the chrome developers release the chrome driver first before releasing the browser.

Anyway, I should add a section on how to find and match your driver and browser versions in one of the vignettes.

gioferreira commented 5 years ago

I'd gladly contribute to that! Not very active on GitHub though, might need some guidance

gioferreira commented 5 years ago

Hi @juyeongkim,

Chrome 75 is out of beta and the issue persists.

Problem is that chrome 74 has a different issue (it looses the cookie in a logged session after a few new windows when - and only when - using headless mode). This is a chromedriver issue, that is solved in 75, but in 75 I can't switch window :(