NoSuchElementException:使用给定的搜索参数无法在页面上找到元素

问题描述 投票:1回答:1

我正在使用的代码:

public class SafariTest {
private static IOSDriver iOSDriver;
private WebElement loginSettingsButton;
@Before
public void preTest() throws MalformedURLException {
    DesiredCapabilities capabilities = new DesiredCapabilities();

    capabilities.setCapability(MobileCapabilityType.DEVICE_NAME, "xxxx");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    capabilities.setCapability(MobileCapabilityType.PLATFORM_VERSION, "12.1");

    capabilities.setCapability(MobileCapabilityType.AUTOMATION_NAME, "XCUITest");
    capabilities.setCapability(MobileCapabilityType.UDID, "xxxx");
    capabilities.setCapability(MobileCapabilityType.APP,"/xxx.app");

    iOSDriver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);

    //webDriver = new AppiumDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
}
@Test
public void testCase(){
    WebDriverWait wait = new WebDriverWait(iOSDriver, 15); 
loginSettingsButton = iOSDriver.findElement(By.name("loginSettingsButton"));
loginSettingsButton.click();
}

@After
public void finishTest(){
    //  webDriver.quit();
}

public static void setContextToWebview(){
    Set<String> availableContexts = iOSDriver.getContextHandles();
    availableContexts.stream()
            .filter(context -> context.toLowerCase().contains("webview"))
            .forEach(newcontext -> iOSDriver.context(newcontext));
}

}

我得到的错误:

org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。有关此错误的文档,请访问:https://www.seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'3.141.59',修订版:'e82be7d358',时间:'2018-11-14T08:17:03'系统信息:主机:'xxxx.local' ,ip:'xxxxx',os.name:'Mac OS X',os.arch:'x86_64',os.version:'10 .14.4',java.version:'1.8.0_152-release'驱动程序信息:io .appium.java_client.ios.IOSDriver Capabilities {app:xxx,automationName:XCUITest,browserName:,databaseEnabled:false,deviceName:xxxx,javascriptEnabled:true,locationContextEnabled:false,networkConnectionEnabled:false,platform:MAC,platformName:iOS,platformVersion :12.1,takeScreenshot:true,udid:xxxx ...,webStorageEnabled:false}会话ID:a2b7627f-9792-4df3-874b-96ced13fc185 ***元素信息:{using = name,value = loginSettingsButton} at sun.reflect。 sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingCo)的sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)中的NativeConstructorAccessorImpl.newInstance0(Native Method) nstructorAccessorImpl.java:45)在java.lang.reflect.Constructor.newInstance(Constructor.java:423)在org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)在org.openqa.selenium org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor .java:158)在io.appium.java_client上的org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)的io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:239)。在oro.openqa的io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)的io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)上的DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42) .selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:323)at io.appium.java_client.DefaultGeneri cMobileDriver.findElement(DefaultGenericMobileDriver.java:62)在io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)在io.appium.java_client.ios.IOSDriver.findElement(IOSDriver.java:1)在org.openqa .selenium.remote.RemoteWebDriver.findElementByName(RemoteWebDriver.java:404)位于io.appium.java_client.AppiumDriver.findElementByName(AppiumDriver.java:1)的io.appium.java_client.DefaultGenericMobileDriver.findElementByName(DefaultGenericMobileDriver.java:118)位于org.openqa.selenium的io.appium.java_client.ios.IOSDriver.findElementByName(IOSDriver.java:1)。在org.openqa.selenium.remote.RemoteWebDriver.findElement上的$ ByName.findElement(By.java:284) RemoteWebDriver.java:315)在io.appium.java_client.DefaultGenericMobileDriver.findElement(DefaultGenericMobileDriver.java:58)在io.appium.java_client.AppiumDriver.findElement(AppiumDriver.java:1)在io.appium.java_client.ios.IOSDriver .findElement(IOSDriver.java:1)at com.example.appiumapplication.SafariTest.testCase(SafariTest.jav)一:63)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)在sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)在sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)在java.lang中位于org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable。)的org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:50)的.reflect.Method.invoke(Method.java:498)。 java:12)atg.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)at org.junit.internal .runners.statements.RunBefores.evaluate(RunBefores.java:26)org.junit.runners.statements.RunAfters.evaluate(RunAfters.java:27)org.junit.runners.ParentRunner.runLeaf(ParentRunner.java) :325)org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)org.junit.runners.BlockJUnit4ClassRunner.runChild( BlockJUnit4ClassRunner.java:57)org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:290)org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:71)at org.junit.runners.ParentRunner .runChildren(ParentRunner.java:288)位于org.junit的org.junit.runners.rarentRunner.access $ 000(ParentRunner.java:58)org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:268)。 runners.ParentRunner.run(ParentRunner.java:363)在org.junit.runner.JUnitCore.run(JUnitCore.java:137)在com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)在com.intellij .rt.execution.junit.IdeaTestRunner $ Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)在com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)在com.intellij.rt.execution.junit .JUnitStarter.main(JUnitStarter.java:70)进程以退出代码255结束

appium hybrid-mobile-app appium-ios
1个回答
0
投票

请尝试使用findElementByAccessibilityId(“loginSettingsButton”),而不是使用findElement(By.Name(“...”))方法

loginSettingsButton = iOSDriver.findElementByAccessibiltyId("loginSettingsButton");

确保loginSettingsButton中存在的元素为automationId,即内容描述

使用name,不建议appium使用xpath。使用appium时必须使用accessibilty id或id。如果您没有cont-desc,resource-id或id等自动化ID,则可以要求开发人员团队添加它

© www.soinside.com 2019 - 2024. All rights reserved.