# Can anybody help me to get xpath of an element

**URL:** <https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948>\
**Category:** Support\
**Created:** [January 22, 2019, 12:53pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948 "2019-01-22T12:53:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jitenderbhardwaj](https://discuss.appium.io/user_avatar/discuss.appium.io/jitenderbhardwaj/32/1744_2.png) [@jitenderbhardwaj](https://discuss.appium.io/u/jitenderbhardwaj)\
**Post date:** [January 22, 2019, 12:53pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948/1 "2019-01-22T12:53:04Z")

</div>

Hello everyone,

I am automating an android application. For inspecting elements i am using uiautomatorviewer. And the element do not have any id associated with it so i was trying to get the xpath of that element. But as far as i know, we need classname in order to create xpath for inspecting any element and the element which i am trying to inspect does not have any classname. I can not share the screenshot/hierarchy of the element which i am trying to inspect as i can not share the application but i found an example of the scenario which i am facing and that is in messenger application. I am attaching the scenario, please have a look to it.  
Any help would be welcomed.

Thanks,  
Jitender

 ![Screenshot_1](https://discuss.appium.io/uploads/default/original/2X/0/00d1b7737050e264c44a2ba603082cd23621b0eb.png)

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 22, 2019, 10:47pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948/2 "2019-01-22T22:47:23Z")

</div>

it looks like webview. try to switch into webview. better never use xpath. try to check upper elements - do they have any ID?

---

<div class="post-metadata">

**Author:** ![jitenderbhardwaj](https://discuss.appium.io/user_avatar/discuss.appium.io/jitenderbhardwaj/32/1744_2.png) [@jitenderbhardwaj](https://discuss.appium.io/u/jitenderbhardwaj)\
**Post date:** [January 24, 2019, 2:08pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948/3 "2019-01-24T14:08:57Z")

</div>

@Aleksei most of the elements do not have ID’s.  
And in order to switch into webview, i must have the locator for the element. But i am unable to locate the elements in webview.

---

<div class="post-metadata">

**Author:** ![Zuzeac](https://discuss.appium.io/letter_avatar_proxy/v4/letter/z/b5a626/32.png) [@Zuzeac](https://discuss.appium.io/u/Zuzeac)\
**Post date:** [January 24, 2019, 2:34pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948/4 "2019-01-24T14:34:13Z")

</div>

does the (2)ViewGroup have an ID? in most cases they should have and you can declare it as a list and then clin on 0, 1 or 2. Can you click on it and share the screenshot?  
or you could try fo find the element by partial content description using People, Chat or Discover string.  
But it’s not the best solution.

> [@How to: find element by partial text of content-description](https://discuss.appium.io/t/how-to-find-element-by-partial-text-of-content-description/16837/4):
>
> try this: driver.findElement(MobileBy.AndroidUIAutomator("new UiSelector().descriptionContains(\""+text+"\"));"));

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [January 25, 2019, 8:41pm UTC](https://discuss.appium.io/t/can-anybody-help-me-to-get-xpath-of-an-element/24948/5 "2019-01-25T20:41:00Z")

</div>

> [@jitenderbhardwaj](#):
>
> And in order to switch into webview, i must have the locator for the element.

wrong. just walk what “driver.context” i available on this screen and if it contains WEBVIEW → switch to it
