Selenium Installation

Selenium installation is the first step to learn automation

1. Python Installation

  • Ensure you have Python installed on your system. You can download it from the official Python website.

  • Verify the installation by running the following command in your terminal or command prompt.
    python –version
  • If it returns the version number, Python is installed.

2. Install Selenium

  • Open a terminal or command prompt and use the following pip command to install Selenium.

    pip install selenium

3. Run the First Selenium Script

from selenium import webdriver
from selenium.webdriver.common.by import By

# Launch a browser
driver = webdriver.Chrome()

# maximize browser window
driver.maximize_window()

#  set implicit wait for 20 sec.
driver.implicitly_wait(20)

# open a facebook URL in the browser
driver.get("https://www.facebook.com")

# send username to field
driver.find_element(By.NAME, "email").send_keys("TestAdmin")

# send password to passwordfield
driver.find_element(By.NAME, "pass").send_keys("Admin@12345")

# click on login button
driver.find_element(By.NAME, "login").click()

# close current browser
driver.close()

Execute script with Firefox

from selenium import webdriver
from selenium.webdriver.common.by import By

# Launch a Firefox browser
driver = webdriver.Chrome()

# maximize browser window
driver.maximize_window()

#  set implicit wait for 20 sec.
driver.implicitly_wait(20)

# open a facebook URL in the browser
driver.get("https://www.facebook.com")

# send username to email field
driver.find_element(By.NAME, "email").send_keys("TestAdmin")

# send password to password field
driver.find_element(By.NAME, "pass").send_keys("Admin@12345")

# click on to login button
driver.find_element(By.NAME, "login").click()

# close current browser
driver.close()