Unable to find button element

Hi can some one help we finding Button element.
i am getting 2 result while searching from its name.
please help me in this.and please write xpath for this…

XPath expression

//UIAApplication//UIAButton[@name=‘0’]

XPath result:
Element=’’
Element=’’

Actual xml:

<?xml version="1.0" encoding="UTF-8"?>

Element=‘UIAButton name=“0” label=“0” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/5" x="-60" y=“334.5” width=“60” height=“80” />’
Element=‘UIAButton name=“0” label=“0” value=“1” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/23" x=“135” y=“7” width=“45” height=“45” />’

try find button by className:
Sample:

    WebElement button1;
    List<WebElement> buttons = driver.findElements(By.className("UIAButton"));

    if (buttons.size() != 0) {
        button1 = buttons.get(0);
        button1.click();
    }

Hi Degard…
can u please send ur mail id…

above code giving me correct button count but not clicking as its value is not 0…
its name is 0

try buttons.get(1);
Seems it is not clicking because x="-60" for first button.

below is the complete xml code…

below is the button highlighted in appium inspector

name: a
type: UIAButton
value:
label: a
enabled: true
visible: false
valid: true
location: {8, 5}
size: {50, 50}
xpath: //UIAApplication[1]/UIAWindow[1]/UIAButton[12]

we need to create xpath

?xml version=“1.0” encoding=“UTF-8”?>
AppiumAUT>
UIAApplication name=“Kitaboo” label=“Kitaboo” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0" x=“0” y=“0” width=“768” height=“1024”>
UIAWindow name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0" x=“0” y=“0” width=“768” height=“1024”>
UIAButton name=“a” label=“a” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/0" x="-60" y=“0” width=“60” height=“80”>
UIAStaticText name=“a” label=“a” value=“a” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/0/0" x="-51" y=“19” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/1" x="-60" y=“80” width=“60” height=“1”>
/UIAImage>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/2" x="-60" y=“253.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=“b” label=“b” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/3" x="-60" y=“253.5” width=“60” height=“80”>
UIAStaticText name=“b” label=“b” value=“b” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/3/0" x="-51" y=“272.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/4" x="-60" y=“333.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=“0” label=“0” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/5" x="-60" y=“334.5” width=“60” height=“80”>
UIAStaticText name=“0” label=“0” value=“0” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/5/0" x="-51" y=“353.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAStaticText name=“0” label=“0” value=“0” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/6" x="-30" y=“349.5” width=“20” height=“20”>
/UIAStaticText>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/7" x="-60" y=“414.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=“d” label=“d” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/8" x="-60" y=“415.5” width=“60” height=“80”>
UIAStaticText name=“d” label=“d” value=“d” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/8/0" x="-51" y=“434.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/9" x="-60" y=“495.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=“f” label=“f” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/10" x="-60" y=“496.5” width=“60” height=“80”>
UIAStaticText name=“f” label=“f” value=“f” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/10/0" x="-51" y=“515.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/11" x="-60" y=“576.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=“Z” label=“Z” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/12" x="-60" y=“577.5” width=“60” height=“80”>
UIAStaticText name=“Z” label=“Z” value=“Z” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/12/0" x="-51" y=“596.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAButton name=“¸” label=“¸” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/13" x="-60" y=“577.5” width=“60” height=“80”>
UIAStaticText name=“¸” label=“¸” value=“¸” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/13/0" x="-51" y=“596.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/14" x="-60" y=“657.5” width=“60” height=“1”>
/UIAImage>
UIAButton name=":" label=":" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/15" x="-60" y=“658.5” width=“60” height=“80”>
UIAStaticText name=":" label=":" value=":" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/15/0" x="-51" y=“677.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAButton name="/" label="/" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/16" x="-60" y=“658.5” width=“60” height=“80”>
UIAStaticText name="/" label="/" value="/" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/16/0" x="-51" y=“677.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAButton name=“¥” label=“¥” value="" dom="" enabled=“false” valid=“true” visible=“false” hint="" path="/0/0/17" x="-60" y=“658.5” width=“60” height=“80”>
UIAStaticText name=“¥” label=“¥” value=“¥” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/17/0" x="-51" y=“677.5” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/18" x="-60" y=“738.5” width=“60” height=“1”>
/UIAImage>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/19" x="-60" y=“911” width=“60” height=“1”>
/UIAImage>
UIAButton name=“g” label=“g” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/20" x="-60" y=“912” width=“60” height=“80”>
UIAStaticText name=“g” label=“g” value=“g” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/20/0" x="-51" y=“931” width=“42” height=“42”>
/UIAStaticText>
/UIAButton>
UIAButton name=“a” label=“a” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/21" x=“8” y=“5” width=“50” height=“50”>
/UIAButton>
UIAButton name=“b” label=“b” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/22" x=“80” y=“7” width=“45” height=“45”>
/UIAButton>
UIAButton name=“0” label=“0” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/23" x=“135” y=“7” width=“45” height=“45”>
/UIAButton>
UIAButton name=“f” label=“f” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/24" x=“190” y=“7” width=“45” height=“45”>
/UIAButton>
UIAButton name=“¸” label=“¸” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/25" x=“245” y=“7” width=“45” height=“45”>
/UIAButton>
UIAButton name=":" label=":" value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/26" x=“300” y=“7” width=“45” height=“45”>
/UIAButton>
UIAButton name="/" label="/" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/27" x=“300” y=“7” width=“45” height=“45”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/27/0" x=“300” y=“7” width=“45” height=“45”>
/UIAImage>
UIAStaticText name="/" label="/" value="/" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/27/1" x=“306.5” y=“13.5” width=“32” height=“32”>
/UIAStaticText>
/UIAButton>
UIAButton name=“i” label=“i” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/28" x=“357” y=“7” width=“45” height=“45”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/28/0" x=“357” y=“7” width=“45” height=“45”>
/UIAImage>
UIAStaticText name=“i” label=“i” value=“i” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/28/1" x=“363.5” y=“13.5” width=“32” height=“32”>
/UIAStaticText>
/UIAButton>
UIAButton name=“L” label=“L” value="" dom="" enabled=“false” valid=“true” visible=“false” hint="" path="/0/0/29" x=“404” y=“7” width=“45” height=“45”>
UIAStaticText name=“L” label=“L” value=“L” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/29/0" x=“415.5” y=“18.5” width=“22” height=“22”>
/UIAStaticText>
/UIAButton>
UIAButton name=“č” label=“č” value="" dom="" enabled=“false” valid=“true” visible=“false” hint="" path="/0/0/30" x=“459” y=“7” width=“45” height=“45”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/30/0" x=“459” y=“7” width=“45” height=“45”>
/UIAImage>
UIAStaticText name=“č” label=“č” value=“č” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/30/1" x=“465.5” y=“13.5” width=“32” height=“32”>
/UIAStaticText>
/UIAButton>
UIAStaticText name=“d” label=“d” value=“d” dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/31" x=“558” y=“10” width=“40” height=“40”>
/UIAStaticText>
UIATextField name="" label="" value=“Search” dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/32" x=“608” y=“15” width=“140” height=“30”>
/UIATextField>
UIAScrollView name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/33" x=“0” y=“0” width=“768” height=“1024”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/33/0" x=“0” y=“0” width=“768” height=“1024”>
/UIAImage>
UIAButton name=“q” label=“q” value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/33/1" x=“708” y="-1" width=“60” height=“60”>
/UIAButton>
UIAActivityIndicator name=“Progress halted” label=“Progress halted” value=“0” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/33/2" x=“374” y=“502” width=“20” height=“20”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/33/2/0" x=“374” y=“502” width=“20” height=“20”>
/UIAImage>
/UIAActivityIndicator>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/33/3" x=“761” y=“1021.5” width=“7” height=“2.5”>
/UIAImage>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/33/4" x=“765.5” y=“1017” width=“2.5” height=“7”>
/UIAImage>
/UIAScrollView>
UIAStaticText name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/34" x=“262” y=“464.5” width=“244” height=“50”>
/UIAStaticText>
UIAStaticText name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/35" x=“262” y=“524.5” width=“244” height=“30”>
/UIAStaticText>
UIAButton name=“Д label=“Д value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/36" x=“20” y=“486” width=“52” height=“52”>
UIAStaticText name=“Д label=“Д value=“Д dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/36/0" x=“22” y=“489” width=“48” height=“48”>
/UIAStaticText>
/UIAButton>
UIAButton name=“Ñ” label=“Ñ” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/37" x=“696” y=“486” width=“52” height=“52”>
UIAStaticText name=“Ñ” label=“Ñ” value=“Ñ” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/37/0" x=“698” y=“489” width=“48” height=“48”>
/UIAStaticText>
/UIAButton>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/38" x=“0” y=“986” width=“280” height=“36”>
/UIAImage>
UIAButton name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/39" x=“259” y=“986” width=“250” height=“36”>
/UIAButton>
UIAStaticText name=“g” label=“g” value=“g” dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/40" x=“315” y=“986” width=“60” height=“36”>
/UIAStaticText>
UIAStaticText name=“Page 3 of 10” label=“Page 3 of 10” value=“Page 3 of 10” dom="" enabled=“true” valid=“true” visible=“true” hint="" path="/0/0/41" x=“375” y=“986” width=“78” height=“36”>
/UIAStaticText>
UIAImage name=“powered_by_kitaboo.png” label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/42" x=“612.5” y=“994” width=“155.5” height=“28”>
/UIAImage>
UIAButton name=“b” label=“b” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/43" x=“8” y=“1028” width=“36” height=“36”>
/UIAButton>
UIASlider name="" label="" value=“22%” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/44" x=“73” y=“1031” width=“622” height=“31”>
/UIASlider>
UIAButton name=“i” label=“i” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/45" x=“348” y=“1028” width=“36” height=“36”>
UIAImage name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/45/0" x=“348” y=“1028” width=“36” height=“36”>
/UIAImage>
UIAStaticText name=“i” label=“i” value=“i” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/45/1" x=“350” y=“1030” width=“32” height=“32”>
/UIAStaticText>
/UIAButton>
UIAButton name=“L” label=“L” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/46" x=“389” y=“1028” width=“36” height=“36”>
UIAStaticText name=“L” label=“L” value=“L” dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/46/0" x=“391” y=“1030” width=“32” height=“32”>
/UIAStaticText>
/UIAButton>
UIAButton name=“9” label=“9” value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/0/47" x=“724” y=“1028” width=“36” height=“36”>
/UIAButton>
/UIAWindow>
UIAWindow name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/1" x=“0” y=“0” width=“768” height=“1024”>
/UIAWindow>
UIAWindow name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/2" x=“0” y=“0” width=“768” height=“1024”>
UIAStatusBar name="" label="" value="" dom="" enabled=“true” valid=“true” visible=“false” hint="" path="/0/2/0" x=“0” y=“0” width=“768” height=“20”>
UIAElement name=“iPad” label=“iPad” value="" dom="" enabled=“true” valid=“true” visible=“false” hint=“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top” path="/0/2/0/0" x=“6” y=“0” width=“25” height=“20”>
/UIAElement>
UIAElement name=“3 of 3 Wi-Fi bars” label=“3 of 3 Wi-Fi bars” value=“HSPUNEDEV” dom="" enabled=“true” valid=“true” visible=“false” hint=“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top” path="/0/2/0/1" x=“36” y=“0” width=“13” height=“20”>
/UIAElement>
UIAElement name=“16:44” label=“16:44” value="" dom="" enabled=“true” valid=“true” visible=“false” hint=“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top” path="/0/2/0/2" x=“369” y=“0” width=“30” height=“20”>
/UIAElement>
UIAElement name=“Not charging” label=“Not charging” value="" dom="" enabled=“true” valid=“true” visible=“false” hint=“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top” path="/0/2/0/3" x=“658” y=“0” width=“74” height=“20”>
/UIAElement>
UIAElement name=“99% battery power, Charging” label=“99% battery power, Charging” value="" dom="" enabled=“true” valid=“true” visible=“false” hint=“Swipe down with three fingers to reveal the notification center., Swipe up with three fingers to reveal the control center, Double-tap to scroll to top” path="/0/2/0/4" x=“738” y=“0” width=“25” height=“20”>
/UIAElement>
/UIAStatusBar>
/UIAWindow>
/UIAApplication>
/AppiumAUT

I haven’t dealt with accessibilityId since my AUT does not yet have any. But your page source doesn’t seem to include any, so perhaps yours has none or they aren’t properly exposed at this time?

With that said, @Degard has the right idea. Since you have multiple elements matching the same “name” what you need to do is come up with something additional that is unique to your target element. Your XML isn’t pasted in as code so it’s getting mangled, so it’s not easy to copy-paste elsewhere to run xpath tests against. But here’s some ideas:

  • Identify some additional attribute(s) that are unique to your target element. @Degard is suggesting the location or size as a start, which seems viable.
  • Utilize xpath axes which will allow you to find the button that is specifically after/before some other unique element.

Here’s an xpath axes example finding a specific table cell (where many exist) within a specific table group:

//UIATableGroup[@name="SPECIAL"]/following-sibling::UIATableCell[@name="All Open Cases"]
1 Like

hi Christopher_Graham,

xpath axes helps me for finding unique element.
but using following or preceding concept will it change in xml code in new builds?

You should try to compose an xpath locator that is a short and concise as possible, while being unique enough to find just the specific element(s) you’re targeting. Avoiding hard coded indexes in your xpath (axes or not) will help negate the chance a UI change in your AUT will break your locator.