gpt4 book ai didi

java - 无法将文本发送到文本框元素

转载 作者:行者123 更新时间:2023-12-01 22:33:37 24 4
gpt4 key购买 nike

我尝试将一些文本发送到 Android 应用程序中的搜索文本框,但它不断返回 NoSuchElement 异常。

以下是从Appium的元素定位器中获取的元素的属性。

enter image description here

以下是将文本发送到搜索框的代码。

driver_App.findElement(By.xpath("//android.widget.EditText[@content-desc='Search']")).sendKeys("ABC");

我已经通过id尝试过

driver_App.findElement(By.id("header-search")).sendKeys("ABC");

按类名

driver_App.findElement(By.className("android.widget.EditText")).sendKeys("ABC");

在某种程度上,以下内容:

new WebDriverWait(driver_App, 30).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='header-search']")));
driver_App.findElement(By.xpath("//*[@id='header-search']")).sendKeys("ABC");

以上都无法将字符串“ABC”发送到文本框元素,并返回 NoSuchElement 异常。

希望就我可能做错的事情以及可能的解决方案提供建议。

注意:添加了以下元素搜索的完整树结构的屏幕截图。

enter image description here

最佳答案

有几种方法可以将字符串发送到移动设备中的文本字段。

一些 Android 文本需要先单击。

new WebDriverWait(driver_App, 30).until(ExpectedConditions.presenceOfElementLocated(By.id("header-search")));
driver_App.findElement (By.id("header-search")).click();
driver_App.findElement (By.id("header-search")).sendKeys ("ABC");

关于java - 无法将文本发送到文本框元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58538648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com