Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»Automation»Setup Selenium with Python and Chrome on Fedora

    Setup Selenium with Python and Chrome on Fedora

    By RahulJune 18, 20223 Mins Read

    Selenium is a versatile tool, which is widely used for automating browser-based tests. It can be used to automate tests for web applications and web services. Selenium supports a number of programming languages, including Java, C#, Python, and Ruby.

    Advertisement

    This makes it possible to write tests in the language that you are most comfortable with. In addition, Selenium has a large user community that provides support and help when needed.

    This tutorial will help you to configure the environment for Selenium with Python and Chrome on Fedora. We will discuss an example written in Python.

    Prerequisites

    Assuming you have access to a Fedora system with a Sudo privileged account.

    This tutorial can be run with GUI access or shell access only.

    Step 1 – Installing Google Chrome

    You can use firefox or Google Chrome web browser to run your selenium test cases. In this article, we will discuss examples with the Google Chrome web browser.

    So, Let’s install Google chrome first. Enable the google-chome repository with the below-mentioned commands:

    sudo dnf install fedora-workstation-repositories 
    sudo dnf config-manager --set-enabled google-chrome 
    

    Now, install the latest google chrome stable web browser:

    sudo dnf install google-chrome-stable 
    

    Google Chrome will be installed on your Fedora system.

    Step 2 – Setup Python Environment

    We will create a virtual environment for running our Python test cases. Follow the below steps to create Python virtual environment, and install the required modules.

    1. Installing Python and its virutal environent module.
      sudo dnf install python3 python3-virtualenv 
      
    2. Create a directory for contianing python environment and scripts..
      mkdir tests && cd tests 
      
    3. Create virutal environment
      python3 -m venv venv 
      source venv/bin/activate 
      
      Creating Python Virtual Environment for Selenium on Fedora
      Creating Python Virtual Environment for Selenium on Fedora
    4. Installing selenium and webdriver manager using PIP under the virtual environemnt.
      pip install selenium webdriver-manager 
      

      Installing selenium for Python on Fedora
      Installing selenium for Python on Fedora

    Step 3 – Running an Example with Selenium Python

    The Python virtual environment is ready to run Selenium scripts. Let’s run an example script, that opens a website in a headless (Useful for remote ssh access) google chrome browser and prints the title of the website.

    Make sure the Python virtual environment is active. you can identify that using the terminal prompt. Now create a Python script and edit it in a text editor.

    nano test1.py 
    

    Copy-paste the below snippet to file:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    from selenium import webdriver
    from selenium.webdriver.chrome.options import Options
    from selenium.webdriver.chrome.service import Service
    from webdriver_manager.chrome import ChromeDriverManager
     
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
     
    driver.get("https://python.org")
    print(driver.title)
    driver.close()

    Press CTRL +O to write changes and then press CTRL + X to exit from the editor.

    Now, run your Python script:

    python test1.py 
    

    You will see the output something like below:

    Running Selenium Python Script on Fedora
    Running Selenium Python Script on Fedora

    At the first run, the script will download the latest chromedriver and place it in your system to use for the next executions.

    In the output, you can see the title of the given website is printed on the screen.

    Conclusion

    Selenium is a popular tool among website testers for running automatic test cases. In this tutorial, we have discussed configuring the Selenium environment with Python scripts.

    google chrome Python selenium
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    What are the Python Static Variables

    Files and Directory Handling in Python

    Files and Directory Handling in Python

    Write a Python Program to Return Multiple Values From a Function

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to List Manually Installed Packages in Ubuntu & Debian
    • 10 Bash Tricks Every Developer Should Know
    • How to Validate Email Address in JavaScript
    • Firewalld: Common Firewall Rules and Commands
    • 12 Apk Commands in Alpine Linux Package Management
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.