Sunday 7 October 2012

How to create a xpath for selenium


Xpath is language using we can get the element of the xml.

So probably you are thinking about how to create xpath using xpath language.

My point of view you should remember below mentioned point whenever you are creating xpath.

1) Always create short xpath.

2) Don’t use dynamic data(Like className,id.. etc) in xpath.

3) If you are feeling that your browser text(like button name ,link text,textbox text etc) are not changing frequently then you should use text only.

Like xpaths for link:-

//*[text()='SignIn']

//*[contains(text(),'Home')]

//*[starts-with(text(),"in your mind)]

for button:-

//*[@value='Login'] or //*[@*='Login']

etc

3) If same page having more than one xpath then use postion or create xpath depending upon the other text/control.

Like:-

//*[@*='Post'][position()=1]

if you want to access last button

//*[@*='Post'][position()=last()]

if all the button/links are getting displayed whenever you are using position=1 then use following xpath and mention postion according your requirment.

(//*[@*='Post'])[position()=3]

create xpath depending upon the other text/control:

//*[text()='Agent Page']/parent::*/parent::*/descendant::*[@*='Post']

for more details about the above mentioned functions refer following link http://www.w3.org/TR/xpath20/.

4) After creating xpath,verify same using xpath checker/firebug/xpather plugin.These are firefox plugin.

if above mentioned plugins are displaying same control as your browser.then your xpath is correct :-)

Tuesday 14 June 2011

How to resolve "Could not start Internet Explorer Application through OLE" issue in Windows 7

1)Open command prompt and run as administrator.
2)Now you can run your IEautomation script.
Now your's script is working fine.

Friday 20 May 2011

IFRAME tag is not working in Win32:IEautomation

if you want to get iframe then use following solution:
1)use SendKeys function for this.
2)if your popup windows is not recognized,then takes the url of popup windows using the regular expression(when link is javascript) otherwise use linkUrl(); for url.
open in same or differnet IE window and use according your requirment.

Win32:IEautomation script hangs after displaying popup window.

1)if this stuation occur then use following solutions:
a)After displaying popup window,it doesn't load page completly,thats why its goes into infinite loop.
so copy exists function and create one more function for click() like ClickWithoutWait() and remove WaitforDone line from this function.
Use ClickWithoutWait() function for displays popup window.

Tuesday 10 May 2011

how to get specific span link using Win32:IEAumation

Copy exists getLink() function and create one more function like getSpanLink().
changed following line
my $links = $agent->Document->links;
to
$inputs = $agent->Document->all->tags("span");

now you can use this function for all the html tag ,those having "span" tag.

how to access specific button using Win32:Ieautomation?

1)Copy exists _getObject function and create a new _getObject(like Sub _getObjectSpecific and add for loop for access spefific button.
2)Now create a any function for specific link/button/list...
For example:for specifc button

sub getSpecificButton{
my ($self, $how, $what,$i) = @_;
my $agent = $self->{agent};
my $buttons = $agent->Document->all->tags("input");
my $target_button = __getObject1($buttons, $how, $what,$i) if ($buttons);
my $button_object;
if ($target_button){
$button_object = Win32::IEAutomation::Element->new();
$button_object->{element} = $target_button;
$button_object->{parent} = $self;
}else{
$button_object = undef;
print "WARNING: No button is present in the document with your specified option $how $what\n" if $warn;
}
return $button_object;
}

How to get specific link using win32:IEautomation

use below link for solution:
http://ieautomationproblems.blogspot.com/2011/05/how-to-access-specific-button-using.html