Open In App

How to set up RSelenium for R?

Last Updated : 18 Mar, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will discuss how to set up RSelenium for the R programming language.

Steps for installation of  RSelenium in RStudio and how to use it:

Step 1: Install Rstudio onto your system.

To install Rstudio on your system, head to the Rstudio website and download the latest version. You can also download the latest version from the RStudio website based on your operating system.

Link: https://www.rstudio.com/products/rstudio/download/

Step 2: Install the Rselenium package in RStudio.

Open up RStudio and type in the following command to install the Rselenium package in RStudio.

install.packages("RSelenium")

This will install the Rselenium package in RStudio and will show you the installation status of the package. This shows the installation is done successfully.

Step 3: Now download the latest version of the web browser that you want to use for automation. If you are using Chrome, then you can download the latest version of Chrome from the Chrome website. And if you are using Firefox, then you can download the latest version of Firefox from the Firefox website.

Step 4: Now, if you have downloaded the chrome or Firefox browser, then you need to download the corresponding WebDriver. After opening chrome, go to the following link to see the installed version of the web browser.

chrome://version

Save the above version information for future use. We need that version information later to download the corresponding WebDriver.

Step 5: To download the Web drivers for Chrome and Firefox, go to the following link.

For chrome: https://sites.google.com/chromium.org/driver/

And download the corresponding WebDriver for your browser version.

Now unzip the download file to the downloads

unzip ~/Downloads/chromedriver.zip -d ~/Downloads

After unzipping, move it to the /local/share and change its permissions to executable.

sudo mv -f ~/Downloads/chromedriver /usr/local/share/
sudo chmod +x /usr/local/share/chromedriver

Here, +x flags mean changing the permission to be executable. 

Step 6: Now create a Rselenium script to open the geeksforgeeks website.

Create a new file named Rselenium.R in the same folder where you have installed Rstudio. Open the file in RStudio and type the following commands.

Script:

R




# R program to demonstrate RSelenium
   
# load the required packages
library(Rselenium)
  
# start the Selenium server
rdriver <- rsDriver(browser = "chrome",
                    port = 2122L,
                    chromever  = "98.0.4758.102",
                    )
   
# creating a client object and opening the browser
obj <- rdriver$client
  
# navigate to the url
   
# closing the browser
obj$close()



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads