1

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]
2
  • 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. Commented Oct 7, 2016 at 9:50
  • Exactly same question : sqa.stackexchange.com/questions/18342/… Commented Feb 23, 2017 at 7:23

4 Answers 4

3

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:

4
  • 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
    Commented Feb 11, 2019 at 12:54
  • @limonik Here both links seems to work. Commented Feb 11, 2019 at 17:41
  • 1
    yes, I updated first one
    – limonik
    Commented Feb 12, 2019 at 7:52
  • @limonik ah, didnt an edit notification, good job! :) Commented Feb 12, 2019 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.