如何在appium测试框架中使用XPath访问并单击反应本机元素?

时间:2019-06-14 13:46:03

标签: android selenium react-native appium

我想使用xpath访问并单击react-native按钮。我正在使用Appium框架进行自动化测试并运行android仿真器。

下面是我的代码:

反应元素:

<Button onPress={ ()=>{this.onPress , Alert.alert("Button Clicked")}}
     title  = "Sign in"
     color="blue"   />

Appium测试文件:

expect(await driver.elementsByXPath("//android.widget.TextView[@text=\'Sign in']")).click();

1 个答案:

答案 0 :(得分:1)

我在webdriver.io上使用以下代码

const webdriverio = require('webdriverio');
const client = await webdriverio.remote(androidOptions); // you have to specify your android options

const element = await client.findElement('xpath', "//android.widget.TextView[@text='Sign in']");
await client.elementClick(element.ELEMENT);