gpt4 book ai didi

java - 使用辅助功能 ID 和 xpath 错误单击菜单

转载 作者:行者123 更新时间:2023-12-02 04:07:35 25 4
gpt4 key购买 nike

我试图单击此菜单,但我没有选择,总是向驱动程序显示一条错误消息,表明该元素不是交互式的,我尝试过使用 xpath、类名和可访问性 id,没有任何效果,有什么意见吗?

id and xPath Menu

dc.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
dc.setCapability("platformName", "android");
dc.setCapability("appPackage", "-----------");
dc.setCapability("appActivity", "-------------------");

AndroidDriver<AndroidElement> driver = new AndroidDriver<AndroidElement>(new URL("http://127.0.0.1:4723/wd/hub"), dc);

MobileElement el1 = (MobileElement) driver.findElementById("email");
el1.sendKeys("-------");
MobileElement el2 = (MobileElement) driver.findElementById("password");
el2.sendKeys("-------");

driver.pressKeyCode(AndroidKeyCode.BACK);
Thread.sleep(1000);

MobileElement el = (MobileElement) driver.findElementById("email_sign_in_button");
el.click();
driver.findElementByXPath("/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.LinearLayout[1]/android.widget.LinearLayout[3]/android.widget.TextView[1]\n").click();
Thread.sleep(4000);

MobileElement e13 = (MobileElement) driver.findElementByXPath("//android.widget.ImageButton[@content-desc=\"open_drawer\"]");
e13.click();


* Element info: {Using=accessibility id, value=open_drawer}
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)
at io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:62)
at io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.findElement(AndroidDriver.java:1)
at io.appium.java_client.FindsByAccessibilityId.findElementByAccessibilityId(FindsByAccessibilityId.java:37)
at Medições.main(Medições.java:44)

最佳答案

不要使用Thread.sleep()永远,它不会增加任何值(value),但会使您的测试变慢。

当您需要等待页面加载或元素变得可用时 - 请使用 Explicit Wait 。在 Selenium/Appium Java 客户端 API 中,您要查找的类是 WebDriverWait

MobileElement e13 = (MobileElement) new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//android.widget.ImageButton[@content-desc=\"open_drawer\"]")));

参见Explicitly wait until visibility of an element using Android driver in Java文章了解更多信息。

关于java - 使用辅助功能 ID 和 xpath 错误单击菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56706445/

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