Skip to main content

Posts

Showing posts from January, 2015

Handling HTML Form Elements.

Almost in every web application, we inputs some values, Selects Options/Checkbox clicks on links/buttons etc through html elements and submit the page and save/retrieve values.

Today we will see how to interact with all these HTML elements (Web Controls).
WebDriver treats all those elements as a same that is WebElement.

below is the list of web controls and their HTML Syntax.


NameHTML SyntaxControlHyper Link<a href="#">Link</a> My Simple LinkText Box<input type="text" value="Some Text"/> Password<input type="password" value="somepass"/> Multiline Textbox<textarea>Firstline Secondline </textarea> Firstline Secondline Checkbox<input name="check1" type="checkbox"/>checkbox 1 <input name="check2" type="checkbox"/>checkbox 2 checkbox 1   checkbox 2Radio Button<input name="options" type="radio" value="Option1" />Optio…

Selecting Date on JQuery Datepicker

Hello Friends,

In this post we will see how to select specific date in JQuery Datepicker.

Its very easy to enter date as text by .sendKeys() method, but mostly when application uses JQuery Datepicker, it disables typing on the text-box. the text-box sets to read only.

While automating such screens we need to write logic which can interact with Datepicker and selects desired date.

Consider below example of Datepicker.


Html code for above example is


To automate this, we first break apart a problem.
Decide which date we want to set Read the current date from datepicker Calculate difference between both dates in Months(difference will positive in case of set date is in future respective to current date & will negative when set date is in past respective to current date of datepicker) Set loop depends on month difference and navigate the datepicker to specific month Select the Day. 
Lets implement the above logic.
Note: we have used Joda Date Time Library for calculate date and time …

Handling Dates in Java

Date is one of the Important Variable type in Java, Generally we use following actions with Dates while Automating the application
1) Read and Write date in Different Format When we read date from browser, it is String type Variable. which is not suitable for perform date like operation. so that we need to convert the string to Date We can convert the string to date using SimpleDateFormat Below is different patterns used

LetterDescriptionExamplesyYear2013MMonth in yearJuly, 07, 7dDay in month1-31EDay name in weekFriday, SundayaAm/pm markerAM, PMHHour in day0-23hHour in am/pm1-12mMinute in hour0-60sSecond in minute0-60Note: If ‘M’ is 3 or more, then the month is interpreted as text, else number
Example 1:

SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy"); String dateString = "07-Jun-2013"; try { Date date = formatter.parse(dateInString); System.out.println(date); System.out.println(formatter.format(date)); } catch (ParseException e) …

Using Actions Class to perform user actions

Hello Friends....

Today we will see how to handle series of events with Selenium WebDriver.

Now you will have question What is Series of events or actions and Where do I need while automating the application?

Have a look in below menu, having 2 Levels of sub menu. 
below is the source HTML of the page

<ul class="top"> <li><a href="#">Menu1</a></li> <li><a href="#">Menu2 >></a> <ul class="sub"> <li><a href="#">SubMenu1</a></li> <li> <a href="#">SubMenu2 >></a> <ul class="sub"> <li><a target="_blank" href="http://www.google.com">Link to Google</a> </li> <li><a href="http://facebook.com">Link to Facebook</a> …

Popular posts from this blog

Alternate Way for sendKeys

One of my friend called me yesterday, he had an interview on Selenium WebDriver and got confused on 1 Question.

What is an alternative for sendKeys Method in WebDriver? I also got stammered on this and thought in mind
Why the hell do we need this? There are below possible reason that I could find, When we need any alternative to sendKeys.
When the Text element is disabled or locked, sendKeys can not set the value in text field.
(in my opinion, this is not the correct way of Automation, because the element is locked or disabled by intend to not allow any text insertion)When we want to write huge text as input... that time the way WebDriver work, by sending Series of characters from String one by one, and Which is Very time consuming. so to minimize that time we can use this alternate method So now we have above two problems with sendKeys ......
Solution!!! The best alternative I found is JavaScript
Way 1 to Execute Script WebDriver driver = new FirefoxDriver(); driver…

Selecting Date on JQuery Datepicker

Hello Friends,

In this post we will see how to select specific date in JQuery Datepicker.

Its very easy to enter date as text by .sendKeys() method, but mostly when application uses JQuery Datepicker, it disables typing on the text-box. the text-box sets to read only.

While automating such screens we need to write logic which can interact with Datepicker and selects desired date.

Consider below example of Datepicker.


Html code for above example is


To automate this, we first break apart a problem.
Decide which date we want to set Read the current date from datepicker Calculate difference between both dates in Months(difference will positive in case of set date is in future respective to current date & will negative when set date is in past respective to current date of datepicker) Set loop depends on month difference and navigate the datepicker to specific month Select the Day. 
Lets implement the above logic.
Note: we have used Joda Date Time Library for calculate date and time …

XPATH Basics....

XPATH Basics...
XPath is a text syntax for locating parts of HTML document XPath contains a library of standard functions which helps to locate the WebElement XPath is a W3C recommendation
XPath uses path expressions to select WebElement or sets of WebElements in Web page. These expressions look very much like the expressions you see when you work with a traditional computer file system. like c:\MyFolder\another_folder\myFile.txt
XPATH terminologies Nodes While using Selenium WebDriver, we come across following three types of nodes
elementattributetext Look at below HTML code sample
Link to GoogleLink to YahooLink to FaceBook here div, a are element nodes (element is the basically type of WebElement). Attribute nodes for div element is class and its value is myLink"a" element has text nodes as Link to Google, Link to Yahoo, Link to FaceBook Relationship of Nodes There are various relations available in XPATH but as a selenium user we must have knowledge of below relations…