Showing posts with label selenium webdriver. Show all posts
Showing posts with label selenium webdriver. Show all posts

Normalize-space is very useful function in XPath when you build it with reference of some string or keyword to use it webdriver script and it has leading or trailing intermediate repeating white space. Normalize-space will strip such unwanted space or white space. In selenium webdriver, very often we use keywords reference in building xpath. If there is not any good reference to build xapth then it is mandatory to use such keywords as reference.

You can look at my post describing different ways to build xpath .

Here i am presenting one example where we will use normalize-space function to build xpath and use it in selenium webdriver test script.

WebDriver interface has many different methods and get method is one of them. WebDriver interface is implemented by different browser classes like ChromeDriver, EdgeDriver, EventFiringWebDriver, FirefoxDriver, InternetExplorerDriver, OperaDriver, RemoteWebDriver and SafariDriver. So you can use get method to open any of these browser with given URL syntax.

get Method
  • Method Name : get
  • Method description : Using HTTP GET operation, It will load new web page in current web browser window. It will block all other operations until the browser load is completed. That means, Next syntax will be executed only after browser loaded completely with given URL.
  • Syntax : driver.get(String arg0)
  • Example : driver.get("");

So in last article we have seen how to locate the WebElement using four locators and those are Name, Id, Partial Link Text and Link Text. Now in this article we are going to see the remaining four locators. Let’s start looking at them one by one.

Locating element By Xpath:
Xpath functions are very useful functions, it help to identify the Elements from its root node as well as from anywhere in the page. As HTML can be an execution of XML (XHTML), Selenium clients can use this amazing language to target WebElement in their web applications. XPath goes beyond (and additionally supporting) the straightforward techniques for situating by id or name attributes, and opens up a wide range of new conceivable outcomes, for example, finding the third checkbox on the page.

In this article, we are going to see how we can locate the web element to perform an action on it. Web element is the elements which are present on a webpage. Button, link, images, text boxes etc. this all are called as web element.

So why do we need to locate the WebElement? The simple answer for this question is, we need to locate the address of each WebElement on which we want to perform actions. Actions like entering the text, copying the text, pressing the buttons etc. actions 

By reading the above paragraph, we hope that you got an idea why we need to locate the WebElement. Now let’s see how we can locate the WebElement.

Today we are going to see the basic things which we are going to use while making the selenium WebDriver scripts using python language. So below is some short example which we are going to see the uses of each line statement

From selenium import webdriver

From selenium.webdriver.common.keys import Keys

driver = webdriver.Firefox ()

driver.get ( "" )

Assert "Python" in driver.title

Element = driver.find_element_by_name ( " address of webelement " )

Element.clear ()

Element.send_keys ( "content text" )

Element.send_keys ( Keys.RETURN )

Assert "No results found." not in driver.page_source

driver.close ()

The above script can be saved to a file (eg: - ), then you can use it like this

Today we are going to see the installation of Python in Eclipse, so that we can use the python as a scripting language for writing the script for selenium WebDriver. Before that let’s see why python is preferred over java.

Preference Python over Java with Selenium  

There is an observation that most of the times python is used with selenium due to following points:
  1. Python is favored programming language as it runs faster than Java programs.
  2. Python uses indentation which is easy to use rather than using traditional braces to start and end block of code while programming.
  3. Python is easy to code due to dynamic typing as compared to static typing in java which can increase chances of syntactical error.
  4. Python is compact and easy to handle as compared to Java.

  • LinkedHashMap class is one of the class of map interface which extends HashMap class and implements Map interface.
  • It is combination of linked list and Hash table implementation of the Map interface and that's why it is called LinkedHashMap.
  • It is maintaining doubly-linked list insertion order in which keys were inserted into the map.
  • It allows to store null elements and optional Map operations are also available.
  • It is non synchronized implementation so if any thread modifies map structurally when map is accessed by multiple threads then it must be synchronized externally.

  • Is is pronounced as HashMap because It is hash table based implementation of map interface.
  • It extends AbstractMap class and implements Map interface.
  • It allows to store null key and null values.
  • It is non synchronized implementation so if multiple threads accessing it concurrently and any one of them modifies it then it must be synchronized externally.
  • It does not guarantee of maintaining the map order.

  • Java Map interface represents the mapping between unique keys to values.
  • Map can not hold duplicate values.
  • In Map interface, Each key can map at most one value.
  • Each Map interface provides three different collection views. Using which you can view map's content as a set of keys, collection of values and set of key-value mappings.
  • Map will helps you when you wants to search, update or delete elements based on it's key.
  • The map interface is implemented by different java classes like HashTable, HashMap and TreeMap.

  • TreeSet is class under Set interface of collection framework.
  • It implements NavigableSet interface which extends SortedSet interface.
  • Elements are ordered by a Comparator which is provided at set creation time or by natural ordering.
  • It maintains the ascending sorting order.
  • TreeSet is not synchronized so if multiple threads accessing it concurrently and any one modifies set entry then it must be synchronized externally.
  • Element's access and retrieval time is very fast from TreeSet so it will much useful when you wants to store large information in ascending order and retrieve any element quickly.
Java TreeSet Class hierarchy

  • SortedSet interface extends Set interface in collection framework of java.
  • As name suggest, It provides total ordering on elements of Set.
  • Set elements will be ordered using their natural ordering or using a comparator interface.
  • All the elements entries of SortedSet must implement Comparable interface.
  • All the elements of SortedSet must be comparable. So e1.compareTo(e2) must not throw ClassCastException.
  • In collection framework, TreeSet class is an implementation for the SortedSet interface.
Java SortedSet Interface hierarchy

It Is most Important to learn shortcuts of eclipse IDE If you wants to speed up Selenium WebDriver test creation and execution process because performing each and every actions In eclipse using just mouse Is time consuming. If you knows keyboard shortcut keys to perform regular actions In eclipse then It will be very easy for you to do It within one second.

  • HashSet is a class of collection framework which extends AbstractSet class and implements the Set interface.
  • HasSet doesn't guarantee that elements order will remain same over the time and returned in any random order.
  • HasSet doesn't allow duplicate values. If you try to insert duplicate, It will overwrite.
  • HasSet allows to store null values.
  • HasSet implementation is not synchronized.
Hashset hierarchy in Java Collection

  • LinkedHashSet Class extends extends HashSet class and Implements Set interface in collection interface hierarchy.
  • LinkedHashSet implementation differs from HashSet as it maintains doubly-linked list running through all of its entries.
  • It maintains element's entries in set as per it's insertion order. So it will allow you insertion order iteration over the set. So when you iterate over LinkedHashSet, In which order it will return elements? Answer is As per it's insertion order.
  • So you will get same copy of elements with the order how they inserted in set. 
  • LinkedHashSetis not synchronized.
LinkedHashSet Class hierarchy

  • Set is one of the collection framework interface which extends root Collections interface.
  • Set collection can not contain duplicate elements.
  • Set interface has all methods which are inherited from Collection interface with special restriction of not allowing duplicate elements.
  • If two Set interface contains same elements then both are equal.
  • Set interface is implemented by LinkedHashSet, HashSet classes and extended by SortedSet interface which is implemented by TreeSet.
Java Set Interface hierarchy

  • If you look at collection hierarchy, Queue extends collection interface.
  • Main purpose of collection is to hold the elements prior to processing.
  • Queue interface provides some additional operations like insertion, inspection and extraction besides collection interface operations.
  • All these three operations exist in 2 different forms. One return special value(null or false depending on the operation) if operation fails else throws an exception if operation fails.
  • Queue follows FIFO(first-in-first-out) so it will insert element at the end of the queue when you insert new element and element will be removed from the beginning of the queue when you remove element.
  • As Queue interface is sub type of collection interface, all methods of collection interface are also available in Queue interface.
Queue Interface hierarchy

  • Stack class in java is one of the collection interface class which is subclass of Vector class.
  • Stake class supports usual push and pop operations.
  • In contrast to queue, Stack class has last-in first-out(LIFO) data structure. So item which is inserted at top will be available first.
  • Stack class extends Vector class of List interface so it includes all methods of vector class and also it has it's own several methods to perform push and pop operations like looking top item from stack, removing top item from stack, push new item at top of stack, searching item from stack and check whether stack is empty.
java stack class example

  • Vector class in java implements List interface of collection framework.
  • Vector class is synchronized.
  • If you don't know size of array then you can use vector class as size of vector can grow and shrink as per adding and removing items.
  • As vector class is synchronized, It will give poor performance on add, delete, update and search operations.
  • Elements of vector can be accessed using it's integer index.
vector class hierarchy in java

  • LinkedList class extends AbstractList class.
  • LinkedList class implements List and Deque interfaces.
  • LinkedList class is using doubly linked list to store elements in list.
  • LinkedList can hold duplicate elements in list.
  • LinkedList is non synchronized.
  • Manipulation is faster in linkedlist as shifting is not required when new element is inserted or deleted from list.
  • You can use it as list, stack or queue as it implements List and Deque interfaces of collection framework.

Earlier have shared many tutorial examples on selenium IDE different commands and Its usage. You can view each of that example on Selenium IDE Tutorial. Still many peoples are using selenium IDE to automate their small web applications and sometimes they needs to perform compatibility testing In Google Chrome and IE browsers like submitting form, registration, login etc. activities.

We can perform these activities very easily In google chrome and IE browsers using Selenium WebDriver and you can view related tutorials link on Selenium Tutorial. Is It possible to run selenium IDE test In Google Chrome? Yes.. Follow steps given bellow to run selenium IDE test In google chrome browser.