Quality is delighting customers
Hi All,
I need help from you all to resolve my query.
I have to click on OK button whose xpath is
xpath=(//button[@id="text_xyz"])[4]
but here the value 4 changes for page refresh
Please help me resolve this.
Thanks,
Balur
Tags:
Permalink Reply by balur on August 28, 2012 at 8:56pm span element for above is
<span class="z">Yes</span><br/> // Yes is a text on button
Permalink Reply by Suresh@Trust on August 29, 2012 at 12:43pm Hi balur,
will u provide the HTML code after locating the button.so that i can give u the exact Xpath for the button
Permalink Reply by balur on August 29, 2012 at 7:49pm thanks for the quick reply.
<button id="searchButtons">
<input type="xyz.button.abc" role="button" value="Search testing"/>
</button>
<span class="z">Yes</span><br/>
Above is the HTML. Waiting for u r quick reply.
However I tried xpath=//span[text()='Yest'] it worked for first time but after refresh it failed to identify the same.
Waiting for helpful reply.
Thanks,
Balur
Permalink Reply by akshay saraswat on August 31, 2012 at 2:32pm Following are few XPath patterns one can use to find dynamic ids.
text
Not yet written - locate elements based on the text content of the node.
starts-with
Many sites use dynamic values for element’s id attributes, which can make them difficult to locate. One simple solution is to use XPath functions and base the location on what you do know about the element. For example, if your dynamic ids have the format (input id="text-12345") where 12345 is a dynamic number you could use the following XPath: //input[starts-with(@id, 'text-')]
contains
If an element can be located by a value that could be surrounded by other text, the contains function can be used. To demonstrate, the element can be located based on the ‘heading’ class without having to couple it with the ‘top’ and ‘bold’ classes using the following XPath: //span[contains(@class, 'heading')]. Incidentally, this would be much neater (and probably faster) using the CSS locator strategy css=span.heading
siblings
Not yet written - locate elements based on their siblings. Useful for forms and tables.
Starting to use CSS instead of XPATH
Locating elements based on class
In order to locate an element based on associated class in XPath you must consider that the element could have multiple classes and defined in any order. However with CSS locators this is much simpler (and faster).
XPath: //div[contains(@class, 'article-heading')]
CSS: css=div.article-heading
Permalink Reply by balur on September 1, 2012 at 9:42am Hi Akshay,
Thanks sharing helpful information.
Can u please post some more examples on CSS.
How to write css for webelements.
Thanks,
Balur
Permalink Reply by pawan kumar on August 31, 2012 at 10:19pm //input[@value='Search testing'] or //span[text()='Yes']
Director - Head of Global Test Center at Barclays
© 2013 Created by Quality Testing.