Saturday, March 1, 2014

Add Cookie option

add_cookie(self, cookie_dict)

Adds a cookie to your current session.

:Args:
 - cookie_dict: A dictionary object, with required keys - "name" and "value";
    optional keys - "path", "domain", "secure", "expiry"

Usage:
    driver.add_cookie({'name' : 'foo', 'value' : 'bar'})
    driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/'})
    driver.add_cookie({'name' : 'foo', 'value' : 'bar', 'path' : '/', 'secure':True})

click_element/click_link when I don't have an id

The HTML code for it:
<li><a href="http://maps.skobbler.com/">Maps</a><span class="beta-tag">beta<span></span></span></li>

Whenever you don't have the ID for an element, use a get_element to find it. For example, here you'd use click_element or click_link with a nested get_element in it:
click_element(get_element(tag='a', href='http://maps.skobbler.com', text='Maps'))


Thursday, May 30, 2013

Setting Firefox Profile To Download File without Asking



 Setting Firefox Profile  To Download File without Asking

Often when downloading files via web automation you encounter a scenario where you want the browser to silently accept the file that is response to an a request.  By setting these preferences in the browser setup, your file is downloaded to the specified path.  Same holds true by changing your settings via about:config.

download_path = '/tmp/download'

profile.set_preference('browser.download.dir', download_path)

profile.set_preference('browser.download.lastDir', download_path)

profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/pdf, application/vnd.fdf, application/x-msdos-program, application/x-unknown-application-octet-stream, application/vnd.ms-powerpoint, application/excel, application/vnd.ms-publisher, application/x-unknown-message-rfc822, application/vnd.ms-excel, application/msword, application/x-mspublisher, application/x-tar, application/zip, application/x-gzip,application/x-stuffit,application/vnd.ms-works, application/powerpoint, application/rtf, application/postscript, application/x-gtar, video/quicktime, video/x-msvideo, video/mpeg, audio/x-wav, audio/x-midi, audio/x-aiff,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
     

profile.set_preference('browser.download.folderList',2)
    
 profile.set_preference('browser.helperApps.alwaysAsk.force',False)

Changing visibility of an Element

Changing Element Visibility

 

Often when writing SST scripts, you'll encounter elements that exists behind divs.  Even when selecting, these elements remain hidden.  You can change the visibility of an element using the following: 


#call the method and pass in an Id ( this can be other attributes)
 cj.change_visibility_show('performanceReportDateDaySelect')


#method that uses javascript to change visibility 

    def change_visibility_show(self,id):
        execute_script('document.getElementById("%s").style.display="block"; ' % id)

You can additional guards using javascript to ensure the element is not already in a visible state.