使用Appium for java的ios UI自动化。无法使用xPath查找元素

时间:2017-03-13 15:45:33

标签: java ios xml xpath appium-ios

我正在尝试使用XPath获取特定元素。我对给定的XML使用以下XPath来获取按钮元素。 它总是显示错误,无法使用指定的源

查找元素
//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[1]

//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[2]

//XCUIElementTypeApplication[1]/XCUIElementTypeWindow[1]/XCUIElementTypeOther[1]/XCUIElementTypeOther[2]/XCUIElementTypeTabBar[1]/XCUIElementTypeButton[3]

XML pagesource是

<?xml version="1.0" encoding="UTF-8"?>
<AppiumAUT>
    <XCUIElementTypeApplication name="TestApp" label="TestApp" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0" x="0" y="0" width="320" height="568">
        <XCUIElementTypeWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0" x="0" y="0" width="320" height="568">
            <XCUIElementTypeOther name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0" x="0" y="0" width="320" height="568">
                <XCUIElementTypeImage name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/0/0/0" x="0" y="0" width="320" height="568">
                </XCUIElementTypeImage>
                <XCUIElementTypeOther name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1" x="0" y="0" width="320" height="568">
                    <XCUIElementTypeTabBar name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1/1" x="0" y="519" width="320" height="49">
                        <XCUIElementTypeButton name="Button1" label="Home" value="true" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1/1/0" x="2" y="520" width="60" height="48">
                        </XCUIElementTypeButton>
                        <XCUIElementTypeButton name="Button2" label="Search" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1/1/1" x="66" y="520" width="60" height="48">
                        </XCUIElementTypeButton>
                        <XCUIElementTypeButton name="Button3" label="Go" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/0/0/1/1/2" x="130" y="520" width="60" height="48">
                        </XCUIElementTypeButton>
                    </XCUIElementTypeTabBar>
                </XCUIElementTypeOther>
            </XCUIElementTypeOther>
        </XCUIElementTypeWindow>
        <XCUIElementTypeWindow name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1" x="0" y="0" width="320" height="568">
            <XCUIElementTypeStatusBar name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0" x="0" y="0" width="320" height="20">
                <XCUIElementTypeOther name="" label="" value="" dom="" enabled="true" valid="true" visible="false" hint="" path="/0/1/0/0" x="0" y="0" width="320" height="20">
                </XCUIElementTypeOther>
                <XCUIElementTypeOther name="" label="" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1" x="0" y="0" width="320" height="20">
                    <XCUIElementTypeOther name="No SIM" label="No SIM" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/0" x="6" y="0" width="41" height="20">
                    </XCUIElementTypeOther>
                    <XCUIElementTypeOther name="3 of 3 Wi-Fi bars" label="3 of 3 Wi-Fi bars" value="SSID" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/1" x="52" y="0" width="13" height="20">
                    </XCUIElementTypeOther>
                    <XCUIElementTypeOther name="4:32 PM" label="4:32 PM" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/2" x="137" y="0" width="50" height="20">
                    </XCUIElementTypeOther>
                    <XCUIElementTypeOther name="StandardLocationTrackingOn" label="Location tracking on" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/3" x="253" y="0" width="9" height="20">
                    </XCUIElementTypeOther>
                    <XCUIElementTypeOther name="Bluetooth on" label="Bluetooth on" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/4" x="268" y="0" width="8" height="20">
                    </XCUIElementTypeOther>
                    <XCUIElementTypeOther name="100% battery power, Charging" label="100% battery power, Charging" value="" dom="" enabled="true" valid="true" visible="true" hint="" path="/0/1/0/1/5" x="282" y="0" width="33" height="20">
                    </XCUIElementTypeOther>
                </XCUIElementTypeOther>
            </XCUIElementTypeStatusBar>
        </XCUIElementTypeWindow>
    </XCUIElementTypeApplication>
</AppiumAUT>

1 个答案:

答案 0 :(得分:1)

// XCUIElementTypeButton [1]

// XCUIElementTypeButton [2]

// XCUIElementTypeButton [3]

以上命令有效。

如果您需要尝试,我已修改您的代码并在下面给出。 (// XCUIElementTypeApplication [1] / XCUIElementTypeWindow [1] / XCUIElementTypeOther [1] / XCUIElementTypeOther)[2] / XCUIElementTypeTabBar [1] / XCUIElementTypeButton [1]