Monday 24 August 2015

Python with Webdriver - launch Firefox and Chrome browser

def setUp_and_login(browser):
        '''
        Supported browsers are: firefox; chrome
        '''
        #
        if browser == 'firefox':
            driver = webdriver.Firefox()
        elif browser == 'chrome':
            driver = webdriver.Chrome('Location of Chromedriver utility')
        else:
            print('')
            print('Browser not recognized, exiting...')
            print('')
            exit()



Sunday 16 August 2015

Purpose of self in Python

from selenium import webdriver
#
Class MyClass:
    def function(self):
        self.driver = webdriver.Firefox()

What is the purpose of SELF here:
"
self is an object reference to the object itself, therefore, they are same. Python methods are not called in the context of the object itself. self in Python may be used to deal with custom object models or something.
"

"
The self variable refers to the object itself.
"

Source:
http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self-in-python
 

Sunday 9 August 2015

Python Modules - how to find location of module sources

Let's assume we want to find the source of Python module Selenium.

In Python Shell:

>>> import selenium
>>>
>>> selenium.__file__
'/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/__init__.pyc'
>>>