如何在ios中找到元素的子元素?

时间:2018-03-02 15:27:23

标签: ios testing automation appium

我无法获得子元素。

我可以在appName inspector

的childNameTV元素下看到childNameLabel元素

示例,我尝试查找第一个子元素的文本;

List<WebElement> webElements = driver.findElements(By.id("childNameTV"));
webElements.get(0).findElement(By.id("childNameLabel")).getText();

enter image description here

然后我收到此错误;

  

org.openqa.selenium.NoSuchElementException:元素不能   位于页面上使用给定的搜索参数。 (警告:   服务器没有提供任何堆栈跟踪信息)命令持续时间或   超时:7.45秒有关此错误的文档,请访问:   http://seleniumhq.org/exceptions/no_such_element.html构建信息:   版本:&#39; 3.0.1&#39;,修订版:&#39; 1969d75&#39;,时间:&#39; 2016-10-18 09:49:13   -0700&#39;系统信息:主持人:&#39; cihangir-macbook.local&#39;,ip:&#39; 10.125.0.57&#39;,os.name:&#39; Mac OS X&#39;,os.arch :&#39; x86_64&#39;,os.version:&#39; 10.13.3&#39;,   java.version:&#39; 1.8.0_131&#39;司机信息:   com.xamarin.testcloud.appium.EnhancedIOSDriver功能   [{app = / Users / cihangirtuna / mobile_app_automation_appium / app / iOS / morhipo.app,networkConnectionEnabled = false,databaseEnabled = false,   deviceName = iPhone 6s Plus,xcodeSigningId = iPhone Developer,   platform = MAC,waitForQuiescence = false,platformVersion = 11.2,   webStorageEnabled = false,locationContextEnabled = false,   automationName = XCUITest,browserName =,takesScreenshot = true,   javascriptEnabled = true,platformName = iOS,   udid = 303257C6-5EE7-410F-87E2-466E3716265C,autoAcceptAlerts = true}]   会议ID:b522404b-4e02-4d4b-a0c9-2b5ffa1b6d51

     

--- 元素信息:{using = id,value = childNameLabel} at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)     在   sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)     在   sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)     at java.lang.reflect.Constructor.newInstance(Constructor.java:423)     在   org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)     在   org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)     在   org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)     在   io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:43)     at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)     在io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)at   org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)     在   io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:37)     at io.appium.java_client.MobileElement.execute(MobileElement.java:1)     at io.appium.java_client.ios.IOSElement.execute(IOSElement.java:1)     在   org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:177)     在   org.openqa.selenium.remote.RemoteWebElement.findElementById(RemoteWebElement.java:210)     在   io.appium.java_client.DefaultGenericMobileElement.findElementById(DefaultGenericMobileElement.java:53)     在   io.appium.java_client.MobileElement.findElementById(MobileElement.java:1)     在   io.appium.java_client.ios.IOSElement.findElementById(IOSElement.java:1)     在org.openqa.selenium.By $ ById.findElement(By.java:218)at at   org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:173)     在   io.appium.java_client.DefaultGenericMobileElement.findElement(DefaultGenericMobileElement.java:45)     在   io.appium.java_client.MobileElement.findElement(MobileElement.java:1)     在   io.appium.java_client.ios.IOSElement.findElement(IOSElement.java:1)     at pages.NewSeasonPage.tabSeasonSubCategory(NewSeasonPage.java:43)     在tests.SortTest.testSortPageOpenWithoutLogin(SortTest.java:31)at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)     在   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     在java.lang.reflect.Method.invoke(Method.java:498)at   org.junit.runners.model.FrameworkMethod $ 1.runReflectiveCall(FrameworkMethod.java:45)     在   org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)     在   org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)     在   org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)     在   org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)     在   org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)     在org.junit.rules.TestWatcher $ 1.evaluate(TestWatcher.java:47)at at   org.junit.rules.RunRules.evaluate(RunRules.java:18)at   org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)at at   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)     在   org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)     在org.junit.runners.ParentRunner $ 3.run(ParentRunner.java:231)at   org.junit.runners.ParentRunner $ 1.schedule(ParentRunner.java:60)at   org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)at at   org.junit.runners.ParentRunner.access $ 000(ParentRunner.java:50)at   org.junit.runners.ParentRunner $ 2.evaluate(ParentRunner.java:222)at at   org.junit.runners.ParentRunner.run(ParentRunner.java:300)at at   org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)     在   org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)     在   org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

1 个答案:

答案 0 :(得分:2)

&#34; childNameLabel&#34;是一个标有&#34; name,&#34;的属性。不是身份证。

我怀疑以下内容适合您:

webElements.get(0).findElement(By.xpath("//XCUIElementTypeStaticText[@name=\"childNameLabel\"]")).getText();