我无法点击文字

时间:2018-07-19 06:01:38

标签: android appium

我试图单击“ WOMEN”,但我不知道为什么它没有单击。 我正在使用java-client 5.0.4appium 1.8.1jdk1.8

有人可以帮助我吗?

我的代码在下面。

driver.findElementByXPath(("//android.widget.TextView[@text='WOMEN']")).click();

enter image description here

日志在这里

[HTTP] 
[HTTP] --> POST /wd/hub/session/03f470f3-6c91-496c-a072-9c2ff1fb0b66/element
[HTTP] {"using":"xpath","value":"//android.widget.TextView[@text='WOMEN']"}
[W3C] Calling AppiumDriver.findElement() with args: ["xpath","//android.widget.TextView[@text='WOMEN']","03f470f3-6c91-496c-a072-9c2ff1fb0b66"]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='WOMEN']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {"cmd":"action","action":"find","params":{"strategy":"xpath","selector":"//android.widget.TextView[@text='WOMEN']","context":"","multiple":false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding '//android.widget.TextView[@text='WOMEN']' using 'XPATH' with the contextId: '' multiple: false

4 个答案:

答案 0 :(得分:0)

您可以使用resource-id和下面提到的命令

使用更可靠的方式
driver.findElement(By.id("complete text in resource-id")).click();

答案 1 :(得分:0)

我更喜欢使用xpath的appium应用程序来显示整个xpath,这对您来说很容易

java-> driver.findElement(By.xpath("//android.widget.EditText[@content-desc=\"testEmail\"]")).click();

答案 2 :(得分:0)

您是否按照以下步骤初始化驱动程序和功能寿命:

AppiumDriver<WebElement> driver;   
DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceName", "Android phone");
caps.setCapability("udid", "your device id");
caps.setCapability("platformName", "Android");
caps.setCapability("platformVersion", "phone version");
caps.setCapability("appPackage", appPackage);
caps.setCapability("appActivity", appActivity);
driver=new AndroidDriver<WebElement>(new URL(
        "http://127.0.0.1:4723/wd/hub"), caps);

如果您已像上面那样初始化了所需的功能和驱动程序,则必须能够使用:

driver.findElement(By.id("your resource id")).click();

或尝试打印

System.out.println(driver.findElement(By.id("your resource id")).getText());

答案 3 :(得分:0)

它在python中,但是您可以将其应用于Java:

recovery_text = 'Forgot your password?'
recovery_psw = self.driver.instance.find_element_by_android_uiautomator('new UiSelector().text("' + recovery_text + '")')
recovery_psw.click()