Friday, January 14, 2011

XPATH Locators

Pattern Meaning
//E an element of type E
//E[@foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar"
//E[contains(text(),"foo")] an E element containing the substring "foo" in its textual contents
//E[contains(@foo,"value")] an E element containing the substring "value" in the attribute foo
//E[@foo="bar" and @foo1="bar1"] an E element whose "foo" attribute value is exactly equal to "bar" and "foo1" attribute value is exactly equal to "bar1"
//E[descendant::F] an E element which contains the F as its child
//E/following-sibling::F an F element which has an adjacent element as E
//E/preceding-sibling::F an F element which is beside E



IDENTIFY AN ELEMENT USING MULTIPLE ATTRIBUTES

Eg: Using XPATH AND CSS


To combine the css locators for multiple attributes use the following way..
css=E[foo='abc'][foo1='abcs'][foo2='abcd'] and so on...
for xpath locators using and u can combine..
//E[@foo="bar" and @foo1="bar1"]
Use getAttribute method to get any element attribte
See the attribute values using firebug suppose

Div Text


to get the style attribute from the above div use some thing like below.
String divStyle = selenium.getAttribute(XPATHOFDIV@style);
String divStyle = selenium.getAttribute(CSSLOCATOR OF DIV@style);
Eg:: String divStyle = selenium.getAttribute(//div[@id='one']@style);
or use CSS locators too..
String divStyle = selenium.getAttribute(css=div[id='one']@style);

Thursday, January 13, 2011

CSS Locators

Pattern Meaning
E an element of type E
E[foo] an E element with a "foo" attribute
E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar"
E[foo~="bar"] an E element whose "foo" attribute value is a list of space-separated values, one of which is exactly equal to "bar"
E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar"
E[foo$="bar"] an E element whose "foo" attribute value ends exactly with the string "bar"
E[foo*="bar"] an E element whose "foo" attribute value contains the substring "bar"
E:nth-child(n) an E element, the n-th child of its parent
E:nth-last-child(n) an E element, the n-th child of its parent, counting from the last one
E:first-child an E element, first child of its parent
E:last-child an E element, last child of its parent
E:only-child an E element, only child of its parent
E:only-of-type an E element, only sibling of its type
E:empty an E element that has no children (including text nodes)
E:active
E:hover
E:focus
an E element during certain user actions
E:enabled
E:disabled
a user interface element E which is enabled or disabled
E:checked a user interface element E which is checked or in an indeterminate state (for instance a radio-button or checkbox)
E:contains("foo") an E element containing the substring "foo" in its textual contents
E#myid an E element with ID equal to "myid".
E:not(s) an E element that does not match simple selector s
E F an F element descendant of an E element
E > F an F element child of an E element
E + F an F element immediately preceded by an E element
E ~ F an F element preceded by an E element

Basic Introduction of selenium

Hi All,
In my opinion selenium is a wonderful tool for automatic web application testing.
I believe selenium testing is a manual testing where a computer see a webpage content using xpath and css locators. To get succeded in selenium concentrate more on the User Interface ....
like how the website is behaving with user actions etc...

For testing a web application using selenium a user has to have aware on this below mentioned things.
  • Locators ( XPath Locators , CSS Locators , DOM locators,Javascript locators)
  • Basic scripting language knowledge
To master in selenium a user has to have good knowledge in locators first and have a basic knowledge on any language like Java,Perl,C# for writing the selenium scripts.So in my opinion learning any testing framework is not a big deal.
To rock in selenium spend dedicated time on learning XPATH and CSS locators first. Later on any testing framework utilization like JUNIT,TESTNG will be an added advantage.

I am about to share knowledge i have on xpath and css locators and dom locators.