Types of xpath 1. Absoulte : xpath starts with single / or starting from Html tag. 2. Relative : xpath starts from // Absolute /html/h1/h2/bodyinput/div = login id /html/h1/h2/body/div/div = password /html/h1/h2/body/div/div/a = login //div[1] Relative: //div[@id='uname'] or //*[@id='uname'] //div[@id='pass'] //a[@id='signin'] Reference: http://www.w3schools.com/default.asp eclipse - site. launch URL http://docs.seleniumhq.org/ download/ textbox input id="q" name="q" go button input id="submit" t //input/a[1] xpath a@id=test css a#test xpath a@class=new css a.new css a[name='q'] nth=child(1) //font/a //font[@id ='addlang']/a Refer: http://docs.seleniumhq.org http://www.w3schools.com/ 1. Xpath 2. Html Base sample given(Below content can be see in the mail sent)
<html>
<h1> </h1>
<h2> </h2>
<body>
<input>
<div id=uname Login Id >
<div id=pass password >
<a id=signin Login >
</body>
</html>
<h1> </h1>
<h2> </h2>
<body>
<input>
<div id=uname Login Id >
<div id=pass password >
<a id=signin Login >
</body>
</html>
Types of xpath
1. Absoulte : xpath starts with single / or starting from Html tag.
2. Relative : xpath starts from //
Absolute
/html/h1/h2/bodyinput/div = login id
/html/h1/h2/body/div/div = password
/html/h1/h2/body/div/div/a = login
My comments: ============ 1. The xpath to find "uname" should not include h1/h2 to identify login id. We need not include same level element.Only hierachial element should be used to identify xpath. The actual xpath should be /html/body/div 2. The xpath to find element "pass" should not include "h1/h2" and also "div" at the same level will be returned as array so it should not be div/div. when it is <div/> <div/> The xpath should be /html/body/div[2] to access second element in div. When it is like div within a div then only the xpath mentioned during session is correct. <div> <div/> </div> For this only the xpath should be /div/div
Leave a Reply