1

This question already has an answer here:

Below are my xpaths and keep on chining, Element path

<div class="dijitInline utilizationTitle">5.00%</div>

Here need to capture values (5.00%)....

Element Xpath

//*[@id="dijit_layout_ContentPane_23"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_24"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_90"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_91"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_151"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_152"]/div[2]/div[1]

marked as duplicate by Bharat Mane, IAmMilinPatel, Chris Kenst, Shailendra Rathore, NarendraC Feb 24 '17 at 4:11

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Try with class name also. But Class name contains 2 elements ( 5.00% and 24.00 % ). Even check with index but getting same issues. Xpath of calss //[@calss="utilizationpanel"][1][1] Here getting both element id. – vishal kaneria Oct 7 '16 at 9:50
  • Exactly same question : sqa.stackexchange.com/questions/18342/… – Michael Roy Feb 23 '17 at 7:23
2

Xpath keeps changing? You can try using other ways to uniquely identify an element, for example, CSS selector.

Unlike Xpath, which focuses on navigation, CSS selector focuses on element attributes.

All of the possible element attributes have something in common,

//*[@id="dijit_layout_ContentPane_23"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_24"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_90"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_91"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_151"]/div[2]/div[1]
//*[@id="dijit_layout_ContentPane_152"]/div[2]/div[1]

all of their id starts with dijit, if you use this following CSS selector:

X[id^='dijit'], this expression reads, locate element X whose attribute id starts with dijit. Once you can locate element X, the rest is easy.

2

Selectors like Xpath and CSS also support parent child relations. You need to find a element in the tree that you can certainly find. From there you can go the N-th child and on and on.

In your case dijit_layout_ContentPane_90 has a parent which you might be able to find with a selector.

Read:

  • Your xpath-axes link is death.I want to try xpath-axes but firstly I need to analyze how the xpaths change. Have you got any idea how can I produce some examples for this condition? – limonik Feb 11 at 12:54
  • @limonik Here both links seems to work. – Niels van Reijmersdal Feb 11 at 17:41
  • 1
    yes, I updated first one – limonik Feb 12 at 7:52
  • @limonik ah, didnt an edit notification, good job! :) – Niels van Reijmersdal Feb 12 at 9:25
0

Most likely following xpath will work

.//*[contains(@id,'dijit_layout_ContentPane')]/div[2]/div[1] 

If it is not working, please provide some HTML.

0

As per my opinion. We should avoid the id or indexing. I am the automation tester and i have seen various application in which id was dynamic and also element changes the place randomly. To handle such kind of situation i tried to make unique xpaths with using various methods, such as starts-with, ends-with, not(contains,'') and contains(,''). So i would suggest use these methods to find the element uniquely.

Not the answer you're looking for? Browse other questions tagged or ask your own question.