Selenium xpath
Selenium xpath are orginally written for xml files.It is very similar to HTML.
When there no id or name in the html expression selenium uses xpath to identify the elements.
For Example:
< input type="submit"
value="login now" valign="absmiddle"/>
In above example there is no id or name so selenium uses xpath to identify the elements to perform the action.
For Example:
< input type="submit"
value="login now" valign="absmiddle"/>
Note : There is no space between "< and Input "in above expression
For above example xpath is
//Input[@value='login now']
Here Input is html tag
@ is attribute symbol
value is Attribute
Login now is value of attribute and it should be case sensitive
Xpath Fails
For Example :
When value=" login now"
' login now' -> xpath fails because of space
Because of space of first letter of first word and/or after last letter of
last word xpath will fails in selenium Rc
//Input[@type='submit']
Some xpath examples
< Input type='text' name='name'>
To find a element
//Input[@name='name'] using attribute value pair
When combination is unique and we cant able to find the element with one attribute-value pair
//Input[@name='name' and @type='text']
For Image
//a[Img[@src='Link of the image']
For Link
Example:
< a href='http:"google.com">
Note : No space between "< and input"
xpath is
1) //a[text()='google'] or
2)//a[@ href=' ' ]
Selenium xpath are orginally written for xml files.It is very similar to HTML.
When there no id or name in the html expression selenium uses xpath to identify the elements.
For Example:
< input type="submit"
value="login now" valign="absmiddle"/>
In above example there is no id or name so selenium uses xpath to identify the elements to perform the action.
For Example:
< input type="submit"
value="login now" valign="absmiddle"/>
Note : There is no space between "< and Input "in above expression
For above example xpath is
//Input[@value='login now']
Here Input is html tag
@ is attribute symbol
value is Attribute
Login now is value of attribute and it should be case sensitive
Xpath Fails
For Example :
When value=" login now"
' login now' -> xpath fails because of space
Because of space of first letter of first word and/or after last letter of
last word xpath will fails in selenium Rc
- space between two words xpath will work in selenium RC
//Input[@type='submit']
Some xpath examples
< Input type='text' name='name'>
To find a element
//Input[@name='name'] using attribute value pair
When combination is unique and we cant able to find the element with one attribute-value pair
//Input[@name='name' and @type='text']
For Image
//a[Img[@src='Link of the image']
For Link
Example:
< a href='http:"google.com">
Note : No space between "< and input"
xpath is
1) //a[text()='google'] or
2)//a[@ href=' ' ]
No comments:
Post a Comment
You Can Post Your Comment Here