In this article, I want to introduce the common keys in Webdriver. The keys are used to simulate a user entering a key on the keyboard. Back space, enter, ALT, ESCAPE; these are the types of keys I am talking about. The place where this would be useful is, for example, the enter key could be used to submit a form in a web application. In the previous Hello World example, we entered the text 'Hello World!' into a search bar and then execute the search with a separate submit command. Another way we could have achieved the same result is to include the enter key at the end of the 'Hello World!' string.
As an example, below is a script to enter text into an input element to search the Yale University course catalog. The search string we will use is 'engl1*' which should return a list of all the one hundred level english courses.
#!/usr/bin/env python
from sys import argv
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
def yale_courses(s):
# start Firefox
driver = webdriver.Firefox()
# navigate to the Yale course catalog
driver.get('http://students.yale.edu/oci/search.jsp')
# find the Course number input page element
input = driver.find_element_by_name('CourseNumber')
# Enter the search string into the input element
input.send_keys(s)
# Take a screen shot
driver.save_screenshot('english_search')
# Execute search
input.send_keys(Keys.RETURN)
# Finished
driver.close()
if __name__=='__main__':
course = argv[1]
yale_courses(course)
Sunday, 31 May 2015
Sunday, 25 January 2015
Python - Extract lines from text file starting with From
Source file:
Let's assume text file containing bunch of lines while some of them start with "From". As an example such a line can look like following:
From louis@media.berkeley.edu Fri Jan 4 18:10:48 2008
What we are trying to do is to parse all the lines from the source file starting with "From" and have them written line by line as a list and at the end count number of lines matching our criteria.
Python code is then as per following:
fname = raw_input("Enter file location: ")
# source file, e.g. C:\Python34\Doc\SourceFile.txt
fh = open(fname)
count = 0
lst = list()
for line in fh:
line = line.rstrip("\n")
if line.startswith("From "):
count = count + 1
lst.append(line.split())
#
# Define initial item in a list
i = 1
for i in lst:
# print second item in each list
print i[1]
#
print "There were", count, "lines in the file with From as the first word"
Example of results:
stephen.marquard@uct.ac.za
louis@media.berkeley.edu
zqian@umich.edu
rjlowe@iupui.edu
zqian@umich.edu
rjlowe@iupui.edu
...
There were 15 lines in the file with From as the first word
Let's assume text file containing bunch of lines while some of them start with "From". As an example such a line can look like following:
From louis@media.berkeley.edu Fri Jan 4 18:10:48 2008
What we are trying to do is to parse all the lines from the source file starting with "From" and have them written line by line as a list and at the end count number of lines matching our criteria.
Python code is then as per following:
fname = raw_input("Enter file location: ")
# source file, e.g. C:\Python34\Doc\SourceFile.txt
fh = open(fname)
count = 0
lst = list()
for line in fh:
line = line.rstrip("\n")
if line.startswith("From "):
count = count + 1
lst.append(line.split())
#
# Define initial item in a list
i = 1
for i in lst:
# print second item in each list
print i[1]
#
print "There were", count, "lines in the file with From as the first word"
Example of results:
stephen.marquard@uct.ac.za
louis@media.berkeley.edu
zqian@umich.edu
rjlowe@iupui.edu
zqian@umich.edu
rjlowe@iupui.edu
...
There were 15 lines in the file with From as the first word
Saturday, 3 January 2015
Python - Parse XML file
# ==================================================================
# >> Short Description:
# Script searches for xml file in given root directory matching
# given pattern and prints selected file to xml
#
# >> Author: Tomas Nemeth
# >> Creation Date: 12/2014
# ==================================================================
#
#-- Import Python modules -----------
import os
import fnmatch
import sys
import xml.etree.ElementTree as ET
from xml.dom import minidom
#------------------------------------
#
#
rootPath = str(input("Insert root path: ")) # e.g. C:\Python34\Doc\ScriptTest
pattern = str(input("Insert file pattern: ")) # including wildcards, e.g. "data*"
print('=================================================')
#
# Search for the files matching given directory & pattern
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
print(os.path.join(root, filename)) # prints the results
#
# User is asked here to select one file from list for parsing
print('=========================================')
file = str(input("Select one file from list for parsing: "))
print('=========================================')
#
# get the root
tree = ET.parse(file)
root = tree.getroot()
#
# Function prints selected file as whole xml
xmldoc = minidom.parse(file)
print(xmldoc.toxml())
#
print('==========================================')
print('')
# >> Short Description:
# Script searches for xml file in given root directory matching
# given pattern and prints selected file to xml
#
# >> Author: Tomas Nemeth
# >> Creation Date: 12/2014
# ==================================================================
#
#-- Import Python modules -----------
import os
import fnmatch
import sys
import xml.etree.ElementTree as ET
from xml.dom import minidom
#------------------------------------
#
#
rootPath = str(input("Insert root path: ")) # e.g. C:\Python34\Doc\ScriptTest
pattern = str(input("Insert file pattern: ")) # including wildcards, e.g. "data*"
print('=================================================')
#
# Search for the files matching given directory & pattern
for root, dirs, files in os.walk(rootPath):
for filename in fnmatch.filter(files, pattern):
print(os.path.join(root, filename)) # prints the results
#
# User is asked here to select one file from list for parsing
print('=========================================')
file = str(input("Select one file from list for parsing: "))
print('=========================================')
#
# get the root
tree = ET.parse(file)
root = tree.getroot()
#
# Function prints selected file as whole xml
xmldoc = minidom.parse(file)
print(xmldoc.toxml())
#
print('==========================================')
print('')
Tuesday, 23 December 2014
Python Web Testing
Web testing using module webbrowser
Usage Examples:
webbrowser.open_new(url)
Open url in a new window of the default browser, if possible, otherwise,
open url in the only browser window.
Example: webbrowser.open_new('http://google.com')
webbrowser.open_new_tab(url)
Open url in a new page (“tab”) of the default browser, if possible,
otherwise equivalent to open_new().
Search for something in Google
Opens new window in default browser.
import webbrowser
#
google = input('Google search: ')
webbrowser.open_new_tab('http://www.google.com/search?btnG=1&q=%s' % google)
Usage Examples:
webbrowser.open_new(url)
Open url in a new window of the default browser, if possible, otherwise,
open url in the only browser window.
Example: webbrowser.open_new('http://google.com')
webbrowser.open_new_tab(url)
Open url in a new page (“tab”) of the default browser, if possible,
otherwise equivalent to open_new().
Search for something in Google
Opens new window in default browser.
import webbrowser
#
google = input('Google search: ')
webbrowser.open_new_tab('http://www.google.com/search?btnG=1&q=%s' % google)
Another Web Testing tutorials
Follow the link below:
Sunday, 14 December 2014
Mobile Applications Testing
Useful link to Wikipedia containing key challenges in Mobile Apps testing and Types of Mobile Apps testing.
http://en.wikipedia.org/wiki/Mobile_application_testing
or another video source of information, quite handy for new starters.
http://en.wikipedia.org/wiki/Mobile_application_testing
or another video source of information, quite handy for new starters.
Monday, 20 October 2014
Credit Check
What does this mean? I did not put so much attention on it until I was rejected when I wanted to get one year contract for mobile phone. Credit check applies for more things, including mortgage, overdraft, credit cards or phone offers.
What is Credit check then?
It is set of input information (for example address, account details, phone number) applicant has to provide in order to be assessed as eligible or not eligible for getting either mortgage or phone contract.
Before you apply for any kind of product where credit check applies, it is good to try credit check home on your own. If you are once rejected in a bank or a phone company, then there is a footprint about you.
See below useful information:
Free credit check and report, get 30 days trial version:
http://www.experian.co.uk/
How to improve your credit score:
http://www.moneysavingexpert.com/loans/credit-rating-credit-score
What is Credit check then?
It is set of input information (for example address, account details, phone number) applicant has to provide in order to be assessed as eligible or not eligible for getting either mortgage or phone contract.
Before you apply for any kind of product where credit check applies, it is good to try credit check home on your own. If you are once rejected in a bank or a phone company, then there is a footprint about you.
See below useful information:
Free credit check and report, get 30 days trial version:
http://www.experian.co.uk/
How to improve your credit score:
http://www.moneysavingexpert.com/loans/credit-rating-credit-score
Sunday, 5 October 2014
Your rights as a tenant
It is quite hard to find trustworthy agency in London and unfortunately quite common that agencies try to do things which are against tenants. It can be hard for those who are newly in London and are not so familiar with their rights.
Following article can help to understand better what your rights are:
Following article can help to understand better what your rights are:
- Your right to pay the same rent
- Your right to live in a safe house
- Your right not to be disturbed
- Your right to have your deposit protected
- Your right not to be harassed
- Your landlord's right to evict you
All explained in Your right as a tenant
Issues with deposit return
I read couple of times about agencies being reluctant to return deposit in a full amount or taking a long time to return it at all.
It's important to know that it is illegal for landlord to pocket your deposit. Once you pay your deposit, then it has to be put to "Tenancy deposit protection scheme".
Links below help to explain all possible issues with deposit:
http://www.thesite.org/housing/renting/deposits-for-renting-7963.html
https://www.gov.uk/deposit-protection-schemes-and-landlords/information-you-must-give-to-your-tenants
Landlord can also lie saying that your deposit is protected even if it is not! For this case there is online checker where you can check it yourself:
http://www.mydeposits.co.uk/tenants/get-started/check-your-deposit
There are couple of cases, when landlord is in advantage and does not have to protect your deposit, mostly depending on type of renting (e.g. long term holiday letting). In such a case the only think which can help is to pay attention before putting signature on contract.
Follow the quiz under the link below to check if your deposit has to be protected:
http://england.shelter.org.uk/get_advice/downloads_and_tools/tenancy_deposit_rights_checker#
Symptoms of being potential victim
List od commonly known scams that tenants have fallen victim to refers to blog where you can read common practices being used. Hope none of them fits yo your case.
http://www.propertyinvestmentproject.co.uk/blog/rental-scams-tenants-should-be-aware-of/
https://www.gov.uk/deposit-protection-schemes-and-landlords/information-you-must-give-to-your-tenants
Landlord can also lie saying that your deposit is protected even if it is not! For this case there is online checker where you can check it yourself:
http://www.mydeposits.co.uk/tenants/get-started/check-your-deposit
There are couple of cases, when landlord is in advantage and does not have to protect your deposit, mostly depending on type of renting (e.g. long term holiday letting). In such a case the only think which can help is to pay attention before putting signature on contract.
Follow the quiz under the link below to check if your deposit has to be protected:
http://england.shelter.org.uk/get_advice/downloads_and_tools/tenancy_deposit_rights_checker#
Symptoms of being potential victim
List od commonly known scams that tenants have fallen victim to refers to blog where you can read common practices being used. Hope none of them fits yo your case.
http://www.propertyinvestmentproject.co.uk/blog/rental-scams-tenants-should-be-aware-of/
Subscribe to:
Posts (Atom)