Step by step instructions to open the Chrome web browser using Rselenium
Step 1: Open up the Rstudio and create a new script named openingChrome.R
Step 2: Import the Rselenium package into the Rstudio by using the following command:
R
library (RSelenium) |
Step 3: Create a new Rselenium server using the Chrome web driver.
R
rdriver <- rsDriver (browser = "chrome" , # browser name port = 8090L, # port number chromever = "98.0.4758.102" , # browser version ) |
This will create a new Rselenium server and will start the Chrome web driver.
Step 4: Create a client object of the Rselenium server to interact with the web browser by using the following command:
R
rseleniumClientObj <- rsDriver$client |
Step 5: Navigate to the URL [https://www.w3wiki.org/] using the following command:
R
|
Step 6: To close the browser and server, run the following command:
R
rseleniumClientObj$ close () |
The above piece of code in R will close the Chrome web browser and the Rselenium server.
Below is the complete implementation.
R
# Opening the Chrome web browser using the RSelenium # load the required packages library (Rselenium) # start the Selenium server rdriver <- rsDriver (browser = "chrome" , # browser name port = 2180L, # port number chromever = "98.0.4758.102" , # chrome browser version ) # creating a client object and opening the browser rseleniumClientObj <- rdriver$client # For navigating to the url # For closing the browser rseleniumClientObj$ close () |
Output:
How to open Google Chrome with RSelenium?
In the article, we are going to learn how to open a Chrome browser using Rselenium package and how to visit a URL. To do so, we must have the following package installed onto our system:
- Java
- R and Rstudio
- Rselenium
- Web Driver
Installation
- Java: We have to install java before using the Rselenium package to avoid any error. We can install Java using the following tutorials:
For Linux: https://www.w3wiki.org/how-to-install-java-jdk9-on-linux/
For Windows: https://www.w3wiki.org/how-to-download-and-install-java-for-64-bit-machine/
For Mac: https://www.w3wiki.org/how-to-install-java-on-macos/
- R and Rstudio: R binary is required to compile the R code. Rstudio is required to run the R code. We can install R and Rstudio by referring the following articles:
For installing R programming language, go to the official site of R programming and download R for Windows(or Mac).
For installing Rstudio you can refer to this article: https://www.w3wiki.org/how-to-install-r-studio-on-windows-and-linux/
- Rselenium: Rselenium is required to automate the web. We can install Rselenium using the following command:
Command:
install.packages(“RSelenium”)
Output:
This will install the Rselenium package into the Rstudio.
- Web Driver: Web Driver is a special package that is required to communicate with the web for automation. We can install the Chrome web driver suitable for our Chrome version from the following link: https://sites.google.com/chromium.org/driver/downloads
Contact Us