Selenium First Example

Let us see a basic example of selenium.Here we are going to launch the webpage in chrome browser using Chrome driver.

Example: In the below example we are launching “ http://www.dummypoint.com/seleniumtemplate.html “ url using chrome driver.

  • Configure the chrome driver to webdriver object.
  • Using get() method of webdriver launch the url.
  • Wait for 5 sec.
  • Close the chrome driver instance.

LaunchWebApp_Chrome.py

from selenium import webdriver
import time

driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/drivers/chromedriver.exe")

driver.get("http://www.dummypoint.com/seleniumtemplate.html")

time.sleep(5)
driver.quit()



Explanation of the program

1. First we need to import the webdriver class from the selenium package to get all the required methods.

from selenium import webdriver


2. Now we need to import the time module to wait for required amount of time before to close the chrome driver instance.

import time


3. Create a object for webdriver class and pass chrome drive path to it.

  
    driver = webdriver.Chrome("/Users/admin/Documents/Skill2Lead/drivers/chromedriver.exe”)

4. Call the get() method using webdriver object(driver) to launch the require url(Webpage).

driver.get("http://www.dummypoint.com/seleniumtemplate.html")


5. Call the sleep() method from imported time module to wait for required amount of time before closing the object.

time.sleep(5)


6. Call the quite() method using webdriver object(driver) to close the driver instance.

driver.quit()