Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selenir session object created - no browser open #28

Open
mapdek opened this issue Sep 2, 2024 · 18 comments
Open

Selenir session object created - no browser open #28

mapdek opened this issue Sep 2, 2024 · 18 comments

Comments

@mapdek
Copy link

mapdek commented Sep 2, 2024

Dear All,

Sorry for my non-knowledge on this.

I ran the following scripts:

selenider_available(session = "rselenium", online = TRUE)

answer = TRUE

session <- selenider_session("rselenium", browser = "chrome", timeout = 4, driver = RSelenium::remoteDriver(port = 4567L, browserName = "chrome"))

A .cmd printscreen comes up (and closes automatically) stating the version of Chrome on my local machine.

image

Then a selenider session object seems open:

image

But I do not see a Chrome browser opening up.

When I try to use the code open_url(), this is the message that comes up:

image

Do you see what I am doing wrong?

Regards,
Marnix

@ashbythorpe
Copy link
Owner

What happens when you run RSelenium::remoteDriver(port = 4567L, browserName = "chrome") on it's own? Is a browser instance created?

{RSelenium} is pretty buggy, and in this case the creation of the selenium client and server is handled by it, so the issue is likely there.

You might be better off using {selenium}, a more up-to-date alternative.

session <- selenider_session(
  "selenium",
  browser = "chrome",
  timeout = 4
)

@mapdek
Copy link
Author

mapdek commented Sep 2, 2024

Dear @ashbythorpe ,

Thank you very much for your quick reply!

Indeed, the reason for me to still use {Rselenium} was because I had been using it but it bugged recently. I wanted to see if it worked with selenider.

Trying RSelenium::remoteDriver(port = 4567L, browserName = "chrome") gives just this, without a browser starting:

image

I would like to switch to {selenium}:

When doing the test, it gives TRUE:

selenider_available(session = "selenium", online = TRUE)

however, when I try the code you stated, this happens, please see the printscreen below:

session <- selenider_session(
  "selenium",
  browser = "chrome",
  timeout = 4
)

image

with more details here:

image

Would you have an idea why the selenium session does not open?

I have added the Chrome.exe in my PATH variable fully at the end by adding this to the existent PATH: ";C:\Program Files\Google\Chrome\Application\chrome.exe" --> or should it be the folder of the chrome.exe and not the .exe itself?

Regards,
Marnix

@ashbythorpe
Copy link
Owner

Can you try running this code:

library(selenium)

server <- selenium_server(interactive = FALSE)

wait_for_selenium_available(error = TRUE)

If this fails (which it should), run:

server$read_output()

server$read_error()

The output should help diagnose the selenium problem.

I've also remembered that RSelenium doesn't work with the latest version of Chrome (ropensci/wdman#34), so it may work if you use a different browser or older Chrome version.

@mapdek
Copy link
Author

mapdek commented Sep 3, 2024

Thanks again!

Running these 3 lines, gives indeed an error:

library(selenium)
server <- selenium_server(interactive = FALSE)
wait_for_selenium_available(error = TRUE)

image

Then running the 2 last lines:

server$read_output()
server$read_error()

gives this output:

image

This is the JAVA version on my laptop:

image

Does this error message mean that the JAVA installation on my desktop needs to be updated to a more recent version?

@ashbythorpe
Copy link
Owner

Yes, you need at least Java 11 to run Selenium (https://www.selenium.dev/blog/2023/java-8-support/). You can download an up-to-date version of Java here: https://www.oracle.com/java/technologies/downloads/

I'm going to try to fix the error messages in selenium so you always see the output of server$read_error().

@mapdek
Copy link
Author

mapdek commented Sep 4, 2024

Dear @ashbythorpe , thank you very much for all your help on this. As i am on a corporate laptop, I will ask our IT desk whether it is possible to download a version 11 or higher of Java.

For information, I also tried reverting back to previous chromedriver.exe for {Rselenium} but it didn't work neither. Could it be that thatis also related to the Java version?

@mapdek
Copy link
Author

mapdek commented Sep 5, 2024

Hi @ashbythorpe , in the mean time Java 11 was installed:

image

When trying to run the following 5 lines:

library(selenium)
server <- selenium_server(interactive = FALSE)
wait_for_selenium_available(error = TRUE)
server$read_output()
server$read_error() 

this error message and accompanying server output come up:

image

With more details on the error:

image

Do you have an idea what this related to?

@mapdek
Copy link
Author

mapdek commented Sep 5, 2024

Actually this evening, I tried again, the 5 lines of codes and this was the message:

library(selenium)
server <- selenium_server(interactive = FALSE)
wait_for_selenium_available(error = TRUE)
server$read_output()
server$read_error() 

image

Could there be something related to the Selenium version (from the printscreen it looks like version: 4.24.0) I am using, related to the Chrome browser (version: 128.0.6613.86)?

@ashbythorpe
Copy link
Owner

Hi, so I've pushed an update to selenium that can handle non-JSON errors. Install it using pak::pak("ashbythorpe/selenium-r") and run the commands again, and we should see what the error is (because I can't reproduce it on my machine).

As for the RSelenium issue, using Chrome is weird because the version of Chrome, the browser itself, and chromedriver have to match. So in order to use RSelenium, you have to use both a prior version of chromedriver and a prior version of Chrome itself (which can be pretty hard to get). I'd strongly recommend using a different browser if you plan on using RSelenium.

@mapdek
Copy link
Author

mapdek commented Sep 10, 2024

Hi @ashbythorpe , thanks again for this.

Running the code to download:
pak::pak("ashbythorpe/selenium-r")

gave this:
image

Then running the 5 lines of codes as previously done:

library(selenium)
server <- selenium_server(interactive = FALSE)
wait_for_selenium_available(error = TRUE)
server$read_output()
server$read_error() 

Gave this:
image

Do you have an idea of what this could be about?

@ashbythorpe
Copy link
Owner

It looks like the installation failed because you don't have the tools to compile packages from source. Try downloading the package from r-universe:
install.packages("selenium", repos = c('https://ashbythorpe.r-universe.dev', 'https://cloud.r-project.org'))

Then try the other commands again.

@mapdek
Copy link
Author

mapdek commented Sep 10, 2024

Ok thanks again!

First I checked whether the version of selenium was the one you sent. It seems to be version selenium_0.1.3.9000, from looking in sessionInfo(). The server$read_output() is also available in the printscreen below :

image

@ashbythorpe
Copy link
Owner

Oh, well it looks like the newest version of selenium is working. Try running your original code with selenider again.

@mapdek
Copy link
Author

mapdek commented Sep 10, 2024

Dear @ashbythorpe , thank you very much, it worked!!

Chrome browser opened up:

image

What was the issue in the end? Was it the Java version on my computer?

@ashbythorpe
Copy link
Owner

I'm not actually sure to be honest, since we didn't actually get to see what the error was. It seems that updating selenium fixed it, but I'm going to keep this issue open for a little bit in case it happens again.

@mapdek
Copy link
Author

mapdek commented Oct 9, 2024

Hi @ashbythorpe , I just wanted to let you know that I have been using selenider since our last communication and it works great! Very smoothly. Thank you very much for all your help again.

@mapdek
Copy link
Author

mapdek commented Oct 25, 2024

Hi @ashbythorpe , hope you're fine! I have one other question about the use of selenider:

sometimes in RStudio, when trying to open a Seleniucm by this code:

session <- selenider_session("selenium", browser = "chrome") a message comes up like this:

image

Then I don't know anything else to do then close RStudio and re-opening and it works.

Is there any code that you would recommend to do this instead of closing and re-opening RStudio?

Regards,
Marnix

@ashbythorpe
Copy link
Owner

I haven't encountered this issue before.

Next time you encounter it, could you see what rlang::last_trace() gives you, to help track down the error?

Also, I would imagine that restarting R (in RStudio, Session -> Restart R) will be quicker than closing and re-opening RStudio itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants