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:
A CentOS 7 server
Root or sudo access
Google Chrome or Mozilla Firefox
Step 1: Install Java
Selenium requires Java to run. You can install Java by following these steps:
$ sudo yum install java-1.8.0-openjdk
Step 2: Install ChromeDriver or GeckoDriver
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
Step 3: Install Selenium
Now, let's install Selenium using the Python package manager, pip:
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.
We have been using your cloud servers for our online store, and we couldn't be happier. The servers are incredibly fast and reliable, ensuring a smooth shopping experience for our customers. Your exceptional customer support team has also been instrumental in addressing our queries promptly. Kudos to your team!
E-commerce Solutions Co.
Your cloud platform has proven to be a crucial asset for our financial services. The robust security measures and data protection protocols have given us peace of mind. Additionally, the high-performance infrastructure has ensured smooth and uninterrupted operations, even during peak periods. We highly recommend your services.
FinTech Solutions Inc.
We couldn't have asked for a better cloud solution provider for our start-up. Your infrastructure is not only reliable but also cost-effective, allowing us to allocate resources efficiently. The scalability options have been crucial as we continue to grow. Thank you for being a trusted partner on our entrepreneurial journey.