We're here to assist with any of your needs, don't hestitate to reach out.
Selenium is a powerful open-source tool for automating web browsers. It allows you to automate browser activities such as filling out forms, clicking buttons, and navigating through web pages. In this guide, we will walk you through the steps to install Selenium on CentOS 7.
Before installing Selenium, make sure you have the following:
Selenium requires Java to run. You can install Java by following these steps:
$ sudo yum install java-1.8.0-openjdk
If you are using Google Chrome, you need to install ChromeDriver. If you are using Mozilla Firefox, you need to install GeckoDriver. Follow the steps below based on the browser you are using:
# Install ChromeDriver dependencies $ sudo yum install -y unzip # Download ChromeDriver $ wget https://chromedriver.storage.googleapis.com/$(curl -sS chromedriver.storage.googleapis.com/LATEST_RELEASE)/chromedriver_linux64.zip # Extract the downloaded archive $ unzip chromedriver_linux64.zip # Move the extracted binary to /usr/bin/ $ sudo mv chromedriver /usr/bin/chromedriver # Add execute permissions to the binary $ sudo chmod +x /usr/bin/chromedriver
# Install GeckoDriver dependencies $ sudo yum install -y libX11 # Download GeckoDriver $ wget https://github.com/mozilla/geckodriver/releases/download/v0.28.0/geckodriver-v0.28.0-linux64.tar.gz # Extract the downloaded archive $ tar -xvf geckodriver-v0.28.0-linux64.tar.gz # Move the extracted binary to /usr/bin/ $ sudo mv geckodriver /usr/bin/geckodriver # Add execute permissions to the binary $ sudo chmod +x /usr/bin/geckodriver
Now, let's install Selenium using the Python package manager, pip:
$ sudo yum install -y python3-pip # Install Selenium $ sudo pip3 install selenium
Finally, let's test if Selenium is successfully installed. Create a new Python file, for example, "selenium_test.py", and add the following code:
from selenium import webdriver # Create a new Chrome or Firefox driver driver = webdriver.Chrome() # for Chrome # driver = webdriver.Firefox() # for Firefox # Open a website driver.get("https://www.example.com") # Print the page title print(driver.title) # Close the driver driver.quit()
Save the file and run it to see if Selenium is working correctly:
$ python3 selenium_test.py
If everything is set up correctly, it should open a browser window, navigate to "https://www.example.com" and print the page title. Once the script finishes, the browser window will close.
Congratulations! You have successfully installed Selenium on CentOS 7.
What our customers say about us
Create your free account today.