菜鸟教程小白 发表于 2022-12-13 04:02:18

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


                                            <p><p>我无法获取子元素。</p>

<p>我可以通过 appium 检查器看到 childNameTV 元素下的 childNameLabel 元素</p>

<p>例如,我尝试查找第一个子元素的文本;</p>

<pre><code>List&lt;WebElement&gt; webElements = driver.findElements(By.id(&#34;childNameTV&#34;));
webElements.get(0).findElement(By.id(&#34;childNameLabel&#34;)).getText();
</code></pre>

<p> <a href="/image/HPh8j.png" rel="noreferrer noopener nofollow"><img src="/image/HPh8j.png" alt="enter image description here"/></a> </p>

<p><strong>然后我得到这个错误;</strong></p>

<blockquote>
<p>org.openqa.selenium.NoSuchElementException: An element could not be
located on the page using the given search parameters. (WARNING: The
server did not provide any stacktrace information) Command duration or
timeout: 7.45 seconds For documentation on this error, please visit:
<a href="http://seleniumhq.org/exceptions/no_such_element.html" rel="noreferrer noopener nofollow">http://seleniumhq.org/exceptions/no_such_element.html</a> Build info:
version: &#39;3.0.1&#39;, revision: &#39;1969d75&#39;, time: &#39;2016-10-18 09:49:13
-0700&#39; System info: host: &#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; Driver info:
com.xamarin.testcloud.appium.EnhancedIOSDriver Capabilities
[{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}]
Session ID: b522404b-4e02-4d4b-a0c9-2b5ffa1b6d51</p>

<p>---<em>Element info: {Using=id, value=childNameLabel}</em>   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at
org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:216)
    at
org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:168)
    at
org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:635)
    at
io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:43)
    at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
    at io.appium.java_client.ios.IOSDriver.execute(IOSDriver.java:1)    at
org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:274)
    at
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)
    at
org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:177)
    at
org.openqa.selenium.remote.RemoteWebElement.findElementById(RemoteWebElement.java:210)
    at
io.appium.java_client.DefaultGenericMobileElement.findElementById(DefaultGenericMobileElement.java:53)
    at
io.appium.java_client.MobileElement.findElementById(MobileElement.java:1)
    at
io.appium.java_client.ios.IOSElement.findElementById(IOSElement.java:1)
    at org.openqa.selenium.By$ById.findElement(By.java:218)   at
org.openqa.selenium.remote.RemoteWebElement.findElement(RemoteWebElement.java:173)
    at
io.appium.java_client.DefaultGenericMobileElement.findElement(DefaultGenericMobileElement.java:45)
    at
io.appium.java_client.MobileElement.findElement(MobileElement.java:1)
    at
io.appium.java_client.ios.IOSElement.findElement(IOSElement.java:1)
    at pages.NewSeasonPage.tabSeasonSubCategory(NewSeasonPage.java:43)
    at tests.SortTest.testSortPageOpenWithoutLogin(SortTest.java:31)    at
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)   at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)   at
org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at
org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at
org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.rules.TestWatcher$1.evaluate(TestWatcher.java:47)at
org.junit.rules.RunRules.evaluate(RunRules.java:18)   at
org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)   at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at
org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at 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
org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)   at
org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)at
org.junit.runners.ParentRunner.run(ParentRunner.java:300)   at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)</p>
</blockquote></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>“childNameLabel”是标记为“名称”的属性,而不是 ID。 </p>

<p>我怀疑以下方法对你有用:</p>

<pre><code>webElements.get(0).findElement(By.xpath(&#34;//XCUIElementTypeStaticText[@name=\&#34;childNameLabel\&#34;]&#34;)).getText();
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在ios中找到元素的子元素?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/49072215/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/49072215/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在ios中找到元素的子元素?