Skip to content

Instantly share code, notes, and snippets.

@sawantuday
Last active December 2, 2016 14:16
Show Gist options
  • Save sawantuday/19ecf0f0420a068d6b2e0d99d7399565 to your computer and use it in GitHub Desktop.
Save sawantuday/19ecf0f0420a068d6b2e0d99d7399565 to your computer and use it in GitHub Desktop.
Selenium quick start with Python
  1. Create virtual environment and activate it (optional)
  2. install selenium with $ pip install selenium
  3. Download chrome driver (or geako for firefox or ghostdriver for phanotm)
  4. Use following code to get started
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome('./chromedriver')
driver.execute_script('window.open()')


driver.close()	// close first window 
driver.close()	// this will reuslt in error 

// to avoide error first switch to window 
driver.switch_to_window(window_name)	// dont know how to get this window_name
// now close window with driver.close() or get new document with driver.get()
driver.close() or driver.get('http://example.com')

// get a list of all open windows 
driver.window_handles
[u'CDwindow-8fbbbee1-0c2f-4a01-aa5b-02b655f5d77f', u'CDwindow-2a7323e8-f540-4703-a56f-086d4bc068e3']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment