菜鸟教程小白 发表于 2022-12-13 12:56:51

java - iOS+appium java客户端: Long press TouchAction does not work?


                                            <p><p>我正在尝试在原生 iOS 应用中自动执行长按触摸操作。</p>

<p>方法1:模拟左上角的长按不起作用。</p>

<p><code>new TouchAction(driver).longPress(0,0).perform()</code>
Appium 日志显示没有错误:</p>

<pre><code>info: 2015-12-21 17:41:19 +0000 Debug: Got new command 5 from instruments: target.touch([{&#34;touch&#34;:[{&#34;x&#34;:0,&#34;y&#34;:0}],&#34;time&#34;:0.2}])
info: 2015-12-21 17:41:19 +0000 Debug: evaluating target.touch([{&#34;touch&#34;:[{&#34;x&#34;:0,&#34;y&#34;:0}],&#34;time&#34;:0.2}])
info: 2015-12-21 17:41:19 +0000 Debug: target.touch(__NSCFArray)
info: 2015-12-21 17:41:20 +0000 Debug: evaluation finished
info: 2015-12-21 17:41:20 +0000 Debug: responding with:
info: 2015-12-21 17:41:20 +0000 Debug: Running system command #6: /usr/local/Cellar/node/4.1.1/bin/node /usr/local/lib/node_modules/appium/node_modules/appium-uiauto/bin/command-proxy-client.js /tmp/instruments_sock 2,{&#34;status&#34;:0,&#34;value&#34;:&#34;&#34;}...
info: Socket data received (25 bytes)
info: Socket data being routed.
info: Got result from instruments: {&#34;status&#34;:0,&#34;value&#34;:&#34;&#34;}
info: Responding to client with success: {&#34;status&#34;:0,&#34;value&#34;:&#34;&#34;,&#34;sessionId&#34;:&#34;332523ee-5a1b-427a-8beb-3c150587d08b&#34;}
</code></pre>

<p>方法二:执行javascript模拟长按</p>

<p><code>((IOSDriver)driver).executeScript("mobile: longClick", ImmutableMap.of("x", 5, "y", 5));</code></p>

<p>Appium 日志异常如下:</p>

<pre><code>TypeError: cb is not a function
    at .iOSController.touchLongClick (/usr/local/lib/node_modules/appium/lib/devices/ios/ios-controller.js:614:3)
    at Object.exports.touchLongClick (/usr/local/lib/node_modules/appium/lib/server/controller.js:371:16)
    at Object.exports.executeMobileMethod (/usr/local/lib/node_modules/appium/lib/server/controller.js:984:22)
    at exports.execute (/usr/local/lib/node_modules/appium/lib/server/controller.js:940:15)
    at Layer.handle (/usr/local/lib/node_modules/appium/node_modules/express/lib/router/layer.js:82:5)
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您必须将 2 个参数传递给 longPress() 方法。它们是您要保持的元素(下面代码中的元素)和时间(2000 毫秒)它必须保持多长时间。</p>

<pre><code>MobileElement element = driver.findElementByClassName(&#34;xxx&#34;);
new TouchAction(driver).longPress(element, 2000).perform();
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于java - iOS&#43;appium java客户端: Long press TouchAction does not work?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/34401593/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/34401593/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: java - iOS&#43;appium java客户端: Long press TouchAction does not work?