Monday, 28 December 2015

Automate the boring stuff with Python

If you are an office worker, student, administrator, or just want to become more productive with your computer, programming will allow you to write code than can automate tedious tasks. 

... And how to begin? There are 3 sources available

Online tutorial:
https://automatetheboringstuff.com/

Or you can buy it as a book on Amazon:
http://www.amazon.co.uk/Automate-Boring-Stuff-Python-Programming/dp/1593275994 

Or you can take an online course on Udemy following the book above, the default price is £48:
https://www.udemy.com/automate/?dtcode=loBQEjb4fb6Z

Or if you want to get the course for free, find it on Youtube:
https://www.youtube.com/channel/UCRjTEkDLPREZNlREZMlotMQ

Wednesday, 14 October 2015

Python Webdriver perform mouseover - hover over an element

Follow simple example below done on site http://www.flipkart.com/. Mouseover is done over menu item ELECTRONICS. Have fun

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
#
driver = webdriver.Firefox()
#
# Test Page = http://www.flipkart.com/
#
driver.get('http://www.flipkart.com')
#
electronics_lnk = driver.find_element_by_xpath('/html/body/div[1]/div[1]/div[2]/div[2]/div/div/ul/li[1]/a/span')
#
hover = ActionChains(driver).move_to_element(electronics_lnk)
driver.implicitly_wait(5)
#
# Pop-up msg appears we need to get rid of it via ESCAPE key
hover.send_keys(webdriver.common.keys.Keys.ESCAPE)
#
driver.implicitly_wait(5)
# mouseover is performed over menu ELECTRONICCS
hover.perform()

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'
>>>