Thursday, August 18, 2011

Selenium Window target = "_blank" issue

For example if you have a link like



Upon click mylink , the url loads into a new window ,  to do some operations in newly opened window it is painful to identify the windowName ..etc

And the solution for that is
selenium.open("/test.html");
selenium.getEval("this.page().findElement(\"link=mylink with target _blank\").target='maddys_window'");
selenium..getEval("selenium.browserbot.getCurrentWindow().open('', 'maddys_window')");
selenium.click("link=mylink with target _blank");
Thread.sleep(2000);
selenium.selectWindow("maddys_window");
selenium.windowFocus();
......
......
selenium.close(); //to close maddys_window
selenium.selectWindow("null");  //to get focus to main window
....
...

Wednesday, August 3, 2011

Qutoes

1. Sun glow for a day, candle for an hour,Matchstick for a minute,Bt a gud day can glow with a SMILE. So start ur day with a SMILE. Have a nice day.

2.Every relationship is like a Cardiogram.. it always has an up and down graph. If its steady , it ends. So accept the ups and down in the life.

3.People say never expect anything from anyone. But the truth is when we really love someone, we naturally expect a little CARE and LOVE from them.

4.Some reasons make relationship precious, but precious relationships r made with No Reasons.. Keep those relations alive forever 4 the life time.

5.If you believe you can do something, then you can acquire the ability to do it even if you didnt have it in the beginning. so first we need TRUST.

6."Communication is the lifeline of any relationship." when you stop communicating, u start loosing ur valuable relationships, so be in touch..!

7.We should not judge a mans merit by his good qualities but by the way how he can use them. we r made richer and beautiful by the reflection of our thought and actions.

8.When you are in the right way u can afford to keep your temper, and when you are in the wrong way you can not afford to lose it.

9. Smile is the best credit card. bcoz it is Accepted worldwide, Auto reload, Unlimited Usage, No Payment, at all. Makes every one Happy.

10.Simple tips 2 play safe in the game of Life (a). Dont PROMISE when u r happy (b). Dont reply when ur ANGRY (c).Dont decide when ur r sad.

11. "Only a few people can feel the rain , others just get wet..!!." , "Only few people can feel the DIVINITY and VIBRATIONS, other just CASUAL"..!! :)

12.Everyday starts with some expectations. But Ends with some experience. That's Life.

13. Clock make sound as Tik Tik but listen carefully its not Tik Tik its real sound is Quick Quick , Because time is precious and never come again.

14.Victory is not the property of brilliants. It is the crown for those who bow themselves in front of hard work and confidence.

15.Best age is Encourage. Best mile is Smile, Best stand is Understand and Best End is Friend , Best day is today. Have every moment of everyday with NONSTOP SMILE.

16.When success is waiting for you, difficulties are blocking the path. Take the weapon of confidence and reach your success every day in your life.

17. The dangerous mistake in the life is the 1st LIE. It leads 2 many lies in order to manage it. ur not able 2 avoid it, even if u dont like, bcaz it beyond 2 u.

18.We have to pray God to provide all aminities to our neighours and enemies more than ourselves. Then the question of Gealous and Ego does not arise.  Only Happy.

19.Every little smile can touch somebody's heart. No one is born Happy. Bt all of us are born with the ability to create happiness.

20. We always feel that life of others is Better than us..! But, we always forget that we are also "Others" for someone else.

21. The greatest gift in life is to find someone who knows all ur faults,differences,mistakes and many more wrongs about you. But still sees the best in U.

22. Three words can narrate the best meaning of life "Expectation kills relation". The Right temperature in a relation is maintained by WARM HEARTS, NOT BY WARM HEADS.

23.Never blame anyone in your life, Gud people in give happiness, Bad people give Experience,Worst people give U A lesson, and Best people give u memories.

 

Wednesday, July 20, 2011

How to do doubleClick on WebElement , WindowMaxmize Using Webdriver

 To maximize the active Window :

public void windowMaximize() {
((JavascriptExecutor) driver).executeScript("if (window.screen){window.moveTo(0, 0);window.resizeTo(window.screen.availWidth,window.screen.availHeight);};");
}

To DoubleClick an Element

public void doubleClick(WebElement webElement) {
//For FF browser.
((JavascriptExecutor)driver).executeScript("var evt = document.createEvent('MouseEvents');"
+ "evt.initMouseEvent('dblclick',true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0,null);"
+ "arguments[0].dispatchEvent(evt);",webElement);

//For IE
//((JavascriptExecutor)driver).executeScript("arguments[0].fireEvent('ondblclick');", webElement);
}

Monday, July 11, 2011

Selenium - Ajax , Selenium - Dojo, ...

Ref: http://www.ibm.com/developerworks/opensource/library/os-webautoselenium/index.html?ca=drs-

Friday, June 3, 2011

how-to-locate-element-which-have-same.html

http://automationtricks.blogspot.com/2010/09/how-to-locate-element-which-have-same.html

Selenium Regular Expression

Selenium supports a few methods that help match text patterns. However, selenium locators don’t accept regular expressions. Only patterns or values accept them.
Globbing:
selenium.click("link=glob:*Gifts"); // Clicks on any link with text suffixed with 'Gifts'
selenium.verifyTextPresent("glob:*Gifts*");
Regular Expressions:[regexp, regexpi]
selenium.click("link=regexpi:^Over \\$[0-9]+$");  //matches links such as 'Over $75', 'Over $85' etc
Contains:
selenium.highlight("//div[contains(@class,'cnn_sectbin')]");  //highlights the first div with class attribute that contains 'cnn_sectbin'
selenium.highlight("css=div#cat_description:contains(\"to last\")");  //locating a div containing the text 'to last' using css selector
Starts-with:
selenium.click("//img[starts-with(@id,'cat_prod_image')]");  //clicks on the first image that has an id attribute that starts with 'cat_prod_image'
selenium.click("//div[starts-with(@id,'tab_dropdown')]/a[last()]");  //clicks on the last link within the div that has a class attribute starting with 'tab_dropdown'
selenium.click("//div[starts-with(@id,'tab_dropdown')]/a[position()=2]"); //clicks on the second link within the div that has a class attribute starting with 'tab_dropdown'
selenium.highlight("css=div[class^='samples']"); //highlights div with class that starts with 'samples'
Ends-with:
selenium.highlight("css=div[class$='fabrics']"); //highlights div with class that ends with 'fabrics'
selenium.click("//img[ends-with(@id,'cat_prod_image')]"); //clicks on the first image that has an id attribute that ends with 'cat_prod_image'
[Note: ends-with is supported only by Xpath 2.0. FF 3 might throw an error for this.]
Ref: http://blog.browsermob.com/2011/02/regular-expressions-and-pattern-matching-with-browsermob-and-selenium/

Way to Get XPATH in IE

Are you stuck with an application that only works in IE?
Do you want the XPATH of an element that can be seen only IE? Unable to replicate the scenario in firefox. There are many firefox addons like xpather, xpath-checker and firebug that will give you the xpath of an element in a second. But sadly there is no addon or tool avaialable that will do this for IE. For most cases you can get the xpath of the elements that fall in your script using the above tools in firefox and tweak them a little (if required) to make them work in IE. But if you are testing an application that will work only in IE or the specific scenario or page that has this element will open-up/play-out only in IE then you cannot use any of the above mentione tools to find the XPATH.
Well the only thing that works in this case is the Bookmarklets that were coded just for this purpose. Bookmarklets are JavaScript code that you will add in IE as bookmarks and later use to get the XPATH of the element you desire. Using these you can get the XPATH as easily as you get using xpather or any other firefox addon.

STEPS TO INSTAL BOOKMARKLETS
1)Open IE
2)Type about:blank in the address bar and hit enter
3)From Favorites main menu select--->Add favorites
4) In the Add a favorite popup window enter name GetXPATH1.
5)Click add button in the add a favorite popup window.
6)Open the Favorites menu and right click the newly added favorite and select properties option.
7)GetXPATH1 Properties will open up. Select the web Document Tab.
8)Enter the following in the URL field.

javascript:function getNode(node){var nodeExpr=node.tagName;if(!nodeExpr)return null;if(node.id!=''){nodeExpr+="[@id='"+node.id+"']";return "/"+nodeExpr;}var rank=1;var ps=node.previousSibling;while(ps){if(ps.tagName==node.tagName){rank++;}ps=ps.previousSibling;}if(rank>1){nodeExpr+='['+rank+']';}else{var ns=node.nextSibling;while(ns){if(ns.tagName==node.tagName){nodeExpr+='[1]';break;}ns=ns.nextSibling;}}return nodeExpr;}

9)Click Ok. Click YES on the popup alert.
10)Add another favorite by following steps 3 to 5, Name this favorite GetXPATH2 (step4)
11)Repeat steps 6 and 7 for GetXPATH2 that you just created.
12)Enter the following in the URL field for GetXPATH2

javascript:function o__o(){var currentNode=document.selection.createRange().parentElement();var path=[];while(currentNode){var pe=getNode(currentNode);if(pe){path.push(pe);if(pe.indexOf('@id')!=-1)break;}currentNode=currentNode.parentNode;}var xpath="/"+path.reverse().join('/');clipboardData.setData("Text", xpath);}o__o();

13)Repeat Step 9.

You are all done!!

Now to get the XPATH of elements just select the element with your mouse. This would involve clicking the left mouse button just before the element (link, button, image, checkbox, text etc) begins and dragging it till the element ends. Once you do this first select the favorite GetXPATH1 from the favorites menu and then select the second favorite GetXPATH2. At his point you will get a confirmation, hit allow access button. Now open up a notepad file, right click and select paste option. This will give you the XPATH of the element you seek.


*I got this bookmarklets from some other site but can't remember which one. Credit goes to the guy who created these JS.
 
Ref: http://deepintoselenium.blogspot.com/2011/05/way-to-get-xpath-in-ie.html