我使用以下代码检查textView和sendKeys:
public static void main(String[] args) throws MalformedURLException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName", "HC48NMZ01687");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", "io.selendroid.testapp");
capabilities.setCapability("app", "C:\\Users\\QA Rahul Singh\\Desktop\\selendroid-test-app-0.17.0.apk");
capabilities.setCapability("appActivity", "HomeScreenActivity");
driver = new AndroidDriver(new URL("https://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
driver.findElement(By.xpath("//android.widget.EditText[@content-desc='my_text_fieldCD']")).sendKeys("rahul");
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
driver.quit();
}
我尝试访问的活动如下所示:
答案 0 :(得分:0)
您可以先使用等待
首先尝试使用Thread.sleep(7000);
等待7-8秒。如果它工作,然后删除它并使用explcit等待
WebDriverWait wait = new WebDriverWait(ad, 100);
wait.until(ExpectedConditions.elementToBeClickable(By."YOUR LOCATOR")).sendKeys(username);
或使用FluentWait
WebElement waitsss(AppiumDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS)
.pollingEvery(1, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}
});
}
如果仍然无效,您的XPath可能不是唯一的,因为它是有效的XPath但可能不是唯一的。您有资源ID使用它如下: -
//android.widget.EditText[contains(@resource-id,'my_text_field')]
希望它会对你有所帮助:)。