# Xpath not working in Katalon but works in Chrome Dev Tools

**URL:** <https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [November 12, 2019, 9:43pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185 "2019-11-12T21:43:20Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sarah.kladstrup](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sarah.kladstrup/32/9513_2.png) [@sarah.kladstrup](https://forum.katalon.com/u/sarah.kladstrup)\
**Post date:** [November 12, 2019, 9:43pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/1 "2019-11-12T21:43:20Z")

</div>

I have an Xpath that Chrome Dev Tools can locate just fine, but Katalon just looks around like John Travolta in Pulp Fiction. Could someone help me pinpoint what I’m doing wrong, please?

Here’s the xpath:  
`//img[contains(@src, 'SR-SE.png') and @ref_element = 'Object Repository/Navpoint/QQ5/QQ5Direct_SytemChooser/iFrame']/parent::div/parent::div/parent::li/preceding-sibling::li/descendant::div[text()='None']`

I’m just trying to verify it is on the page and is previous to SR-SE.png:  
`WebUI.waitForElementPresent(findTestObject('Object Repository/Navpoint/QQ5/Reels/Mount_DropDown_None_option-InRelationToSE'), 10)`

Here are the logs:

1. `2019-11-12 15:26:19.021 DEBUG testcase.Reels_Mount_Brackets_Order - 14: waitForElementPresent(findTestObject("Object Repository/Navpoint/QQ5/Reels/Mount_DropDown_None_option-InRelationToSE"), 10)`

2. `2019-11-12 15:26:29.389 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by 'By.xpath: //img[contains(@src, 'SR-SE.png') and @ref_element = 'Object Repository/Navpoint/QQ5/QQ5Direct_SytemChooser/iFrame']/parent::div/parent::div/parent::li/preceding-sibling::li/descendant::div[text()='None']'. Please recheck the objects properties to make sure the desired element is located.`

3. `2019-11-12 15:26:29.396 WARN k.k.c.w.k.b.WaitForElementPresentKeyword - Object 'Object Repository/Navpoint/QQ5/Reels/Mount_DropDown_None_option-InRelationToSE' is not present after 10 second(s)`

Here’s a screen shot of the element and it’s HTML.

 ![2019-11-12%2015_31_44-MountBracketsXPathNotWorking](https://europe1.discourse-cdn.com/katalon/original/2X/9/99c46bce6a6b8bbf68acab0f6745db7b0472c149.jpeg)

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [November 12, 2019, 10:14pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/2 "2019-11-12T22:14:32Z")

</div>

This css will select the `UL` element:

```css
#mountDropdown_listbox

```

This will select the first child `LI` element

```css
#mountDropdown_listbox > li

```

This will select the `div` element highlighted in your image.

```css
#mountDropdown_listbox > li > div > div

```

One of the problems with xpath, while it’s a notional standard, implementors don’t draw from a common source (or spend much time verifying it works).

---

<div class="post-metadata">

**Author:** ![sarah.kladstrup](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sarah.kladstrup/32/9513_2.png) [@sarah.kladstrup](https://forum.katalon.com/u/sarah.kladstrup)\
**Post date:** [November 13, 2019, 2:20pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/3 "2019-11-13T14:20:21Z")

</div>

Russ,

Thank you!

The thing Xpath provides me in this case is the ability to key off another element. I want to verify that the “None” is above the “Bracket SE”, for example.  
Is there another/better way to do that?

Thanks,  
Sarah

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [November 13, 2019, 2:32pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/4 "2019-11-13T14:32:52Z")

</div>

Sorry, I didn’t mean to lead you astray. There is no “contains” or text() equivalent in CSS. You can either fix whatever is wrong with your original xpath, or use a combination of CSS and JavaScript. For the former, I’m not you’re guy. For the latter (assuming you need the help) let me know.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 13, 2019, 6:08pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/5 "2019-11-13T18:08:47Z")

</div>

> [@sarah.kladstrup](#):
>
> I’m just trying to verify it is on the page and is previous to SR-SE.png

Try this approach out:

1.) Try this xpath:

`//ul[@id='mountDropdown_listbox']/li[.//div[text()='None'] and ./following-sibling::li[.//div[text()='Bracket SE']]`

In plain english:

_The list item (the `<li>` element) within the “Mount Options” dropdown (the `<ul>` element) which has the text ‘None’ and also has a following sibling list item which has the text ‘Bracket SE’_.

2.) Usually, you would use the [waitForElement\_\_()](https://docs.katalon.com/katalon-studio/docs/webui-wait-for-element-present.html) family of methods as a way to handle timing, and not as a way to validate the presence/non-presence of something. For “verifying it is on the page”, you should probably use the [verifyElement\_\_()](https://docs.katalon.com/katalon-studio/docs/webui-verify-element-present.html) family of methods instead:

`WebUI.verifyElementPresent(findTestObject('path/to/my/object'), 10)`

This will act as a true **assertion** , and will fail the test if evaluated to false. When you instead use the waitForElementPresent() method as you have, you can see that you’ve just gotten a warning (#3 from your original post) and the test will continue regardless, which I’m assuming is not what you want.

Let me know if this works for you! 😄

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [November 13, 2019, 6:15pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/6 "2019-11-13T18:15:26Z")

</div>

> [@Brandon\_Hein](#):
>
> This will act as a true **assertion** ,

no, will not. see recent topics on this matter

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 13, 2019, 6:16pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/7 "2019-11-13T18:16:00Z")

</div>

Links… ?

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [November 13, 2019, 6:17pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/8 "2019-11-13T18:17:15Z")

</div>

@Brandon_Hein  
one of them:

> [@FailureHandling Change breaks legacy code (was STOP\_ON\_FAILURE does not stop a test when verifyElementPresent returns false)](http://forum.katalon.com/t/stop-on-failure-does-not-stop-a-test-when-verifyelementpresent-returns-false/36075/28):
>
> verifyElementPresent checks for null parameter and return false, so that’s why your test seems to ignore the FailureHandling flag, it is debatable wether or not we should throw exception when the parameter is null or just return false. However, as a way to demonstrate my point regarding the kind of failures that FailureHandling would assist you with, considering the test case with just one line, no opening web driver or anything: WebUI.verifyElementPresent(new TestObject(), 10, FailureHandling…

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 13, 2019, 6:23pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/9 "2019-11-13T18:23:08Z")

</div>

@Ibus Thanks, I also do not use the WebUI API, so I was not aware of this. The verifyElement\_\_() and waitForElement\_\_() methods have been a point of contention for a while. I even posted on it way back in the day:

> [@Remove timeOut argument from verifyElement\_\_\_() family of methods](http://forum.katalon.com/t/remove-timeout-argument-from-verifyelement-family-of-methods/17768):
>
> This is part suggestion, part inquiry on my part as to the thinking behind the current verifyElement\_\_\_() methods and their waitForElement\_\_\_() counterparts, and is a conglomeration of things that myself and others harped on before (see links provided at the bottom). As a general approach, both semantically and functionally, it would make sense that these two families of methods serve related, yet separate purposes. Specifically: 1.) verifyElement\_\_\_() methods should act solely as assertions, …

@sarah.kladstrup In that case, if you indeed want the test to stop on failure, a simple approach would be to just assert the result of the verifyElementPresent() call, which I believe returns a boolean value:

`assert WebUI.verifyElementPresent(findTestObject('path/to/my/object'), 10)`

Or to join the rest of us, and implement your own framework 🙂

---

<div class="post-metadata">

**Author:** ![Ibus](https://avatars.discourse-cdn.com/v4/letter/i/e9a140/32.png) [@Ibus](https://forum.katalon.com/u/Ibus)\
**Post date:** [November 13, 2019, 6:25pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/10 "2019-11-13T18:25:48Z")

</div>

@Brandon_Hein it’s a recent update which changed the behaviours … we still debate on what is the best aproach.

until a decision will be taken, assert is a good workaround (but note that this may change also)

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 14, 2019, 7:31pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/11 "2019-11-14T19:31:32Z")

</div>

@sarah.kladstrup Curious if any of this has helped. Were you able to get something working?

---

<div class="post-metadata">

**Author:** ![sarah.kladstrup](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sarah.kladstrup/32/9513_2.png) [@sarah.kladstrup](https://forum.katalon.com/u/sarah.kladstrup)\
**Post date:** [November 14, 2019, 7:36pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/12 "2019-11-14T19:36:05Z")

</div>

@Brandon_Hein I liked your suggestion of  
`//ul[@id='mountDropdown_listbox']/li[.//div[text()='None'] and ./following-sibling::li[.//div[text()='Bracket SE']]`  
but that did not work, unfortunately. I still have some troubleshooting to do here.

I will use the `assert` functionality, however.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 14, 2019, 10:48pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/13 "2019-11-14T22:48:47Z")

</div>

One other thought: Are you working with iframes (does the element you are trying to work with live within an `<iframe>` element)? This can affect element location a lot of the time.

---

<div class="post-metadata">

**Author:** ![sarah.kladstrup](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sarah.kladstrup/32/9513_2.png) [@sarah.kladstrup](https://forum.katalon.com/u/sarah.kladstrup)\
**Post date:** [November 15, 2019, 1:40pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/14 "2019-11-15T13:40:45Z")

</div>

Yes, but all my objects have their parent iFrame included by Katalon.  
To clarify: in every object, I have selected the iFrame using Katalon’s “Have Parent Object?” setting.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 15, 2019, 5:01pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/15 "2019-11-15T17:01:48Z")

</div>

> [@sarah.kladstrup](#):
>
> To clarify: in every object, I have selected the iFrame using Katalon’s “Have Parent Object?” setting.

I strongly believe this is part of your problem. Historically, the “Have Parent Object” functionality is very hit-or-miss (see [this](http://forum.katalon.com/t/unable-to-click-in-object-associated-with-iframe/21007/3) post). Instead, try removing that property from your test object, create a new test object that locates the parent frame, and handle switching to it yourself as a separate test step, like this:

```
WebUI.switchToFrame(findTestObject('path/to/iframe/object'), 10)
assert WebUI.verifyElementPresent(findTestObject('path/to/my/object'), 10)

```

Note: If the particular iframe that the element in question lives in is further nested in other iframes, you will of course need multiple switchToFrame() calls to get down to the correct one.

---

<div class="post-metadata">

**Author:** ![sarah.kladstrup](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/sarah.kladstrup/32/9513_2.png) [@sarah.kladstrup](https://forum.katalon.com/u/sarah.kladstrup)\
**Post date:** [November 15, 2019, 5:40pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/16 "2019-11-15T17:40:18Z")

</div>

@Brandon_Hein While I think that’s a good idea in generally, I don’t have this issue with any of the dozens of other objects in the same module/application. And it’s not the element itself. I have a second object that Katalon uses to interact with it successfully, and again, it has the same parent iFrame included.

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [November 15, 2019, 6:09pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/17 "2019-11-15T18:09:55Z")

</div>

Sarah, take a look at this…

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/8/87f5170fcd599169f6c201a1de838968ff10123e.png)  
  

More here: **[Groovy(JavaScript(CSS))](http://forum.katalon.com/t/how-to-groovy-javascript-css-using-css-selectors-in-javascript-in-groovy-in-test-cases/34488)**

Let me know if you want to try it.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 15, 2019, 6:14pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/18 "2019-11-15T18:14:23Z")

</div>

Fair enough. At the very least, instead of removing the parent iframe setting altogether as I’ve suggested, you could try creating a test object for the iframe and switching to the frame yourself once, just to see if it works. At least then, you can narrow down what’s actually giving you trouble 🙂

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [November 15, 2019, 6:28pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/19 "2019-11-15T18:28:31Z")

</div>

`By.xpath: //img[contains(@src, 'SR-SE.png') and @ref_element = 'Object Repository/Navpoint/QQ5/QQ5Direct_SytemChooser/iFrame']/parent::div/parent::div/parent::li/preceding-sibling::li/descendant::div[text()='None']`

Somehow this xpath looks strange to me, perhaps a little bit overwhelmed, so I need to test the assumption that it’s correct. Can you confirm (by image preferably) that when you paste this xpath into the Inspection Tool, it successfully highlights your object ? Please do the same with with Brandon’s xpaths.

Because in the xpath I see that it has information of Katalon (namely the part ‘Object Repository’) which the Web Driver will never know, therefore I highly doubt that this is the correct XPath. Exploring @Brandon_Hein’s direction, please post the image of your Test Object.

Another direction, from the image you posted there is a pre-condition (clicking or hovering on the select) to the presence of that element, please confirm that at the time the test fails, you can visually see the element.

Please also share the full script, and the full console log, cause maybe we may see a clue there.

---

<div class="post-metadata">

**Author:** ![Brandon\_Hein](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/brandon_hein/32/1092_2.png) [@Brandon\_Hein](https://forum.katalon.com/u/Brandon_Hein)\
**Post date:** [November 15, 2019, 6:33pm UTC](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185/20 "2019-11-15T18:33:29Z")

</div>

> [@ThanhTo](#):
>
> Somehow this xpath looks strange to me

I had the same thought, because that xpath in no way reflects what is in the screenshot of the HTML for the target element. I based my suggestion for an xpath on the HTML screenshot, hence why it looks so different than the one in the OP.

[Next page](https://forum.katalon.com/t/xpath-not-working-in-katalon-but-works-in-chrome-dev-tools/36185.md?page=2)
