简体   繁体   English

Sendkeys 在使用 Appium 的 iOS 真实设备中不起作用

[英]Sendkeys not working in iOS real device using Appium

I am using appium (v1.10.0) for automating iOS native app on macOS(10.13.6) using Xcode 10.1 on a real device (iPhone 6s) of platform version 12.1.3.我正在使用 appium (v1.10.0) 在平台版本 12.1.3 的真实设备 (iPhone 6s) 上使用 Xcode 10.1 在 macOS(10.13.6) 上自动化 iOS 本机应用程序。 When I start appium server and start session, the app will open in the device.当我启动 appium 服务器并启动会话时,该应用程序将在设备中打开。 Once I run the code in eclipse to send the Username to login page of the app, mobile keyboard is not getting opened and hence sendkeys() is not working.一旦我在 eclipse 中运行代码将用户名发送到应用程序的登录页面,移动键盘就没有打开,因此 sendkeys() 不起作用。

Tried getKeyboard() before sendkeys().在 sendkeys() 之前尝试过 getKeyboard()。 Still the error exists.错误仍然存​​在。 Below is the code which I tried.下面是我试过的代码。

DesiredCapabilities cap = new DesiredCapabilities();

    cap.setCapability("device", "iPhone");

    cap.setCapability("deviceName", "iPhone 6s");

    cap.setCapability("platformVersion", "12.1.3");

    cap.setCapability("platformName", "iOS");

     
    cap.setCapability("app","/Users/TP/Desktop/SampleApp.ipa" );

    cap.setCapability("udid", "xxxxxxxxxxxxxxxxxxx");

    cap.setCapability("automationName", "XCUITest");

    cap.setCapability("xcodeOrgId", "xxxxxxxx");

    cap.setCapability("xcodeSigningId", "xxxxxxxx");
    
    driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), cap);
        
    driver.findElement(By.xpath("//XCUIElementTypeApplication[@name=\"TBI\"]")).click();
                
    driver.getKeyboard().sendKeys("abc");

Mobile keyboard is not getting opened and hence throwing the following error.移动键盘未打开,因此引发以下错误。

org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. org.openqa.selenium.WebDriverException:处理命令时发生未知的服务器端错误。

Original error: Error Domain=com.facebook.WebDriverAgent Code=1 "Only actions of 'pointer' type are supported. 'key' is given instead for action with id 'keyboard'" UserInfo={NSLocalizedDescription=Only actions of 'pointer' type are supported.原始错误:错误域=com.facebook.WebDriverAgent 代码=1“仅支持‘指针’类型的操作。为 id 为‘键盘’的操作提供‘key’” UserInfo={NSLocalizedDescription=仅‘指针’的操作支持类型。 'key' is given instead for action with id 'keyboard'} 'key' 代替 id 'keyboard'}

你不需要使用getKeyboard()你可以直接将值发送到字段

Send Keys sends a sequence of key strokes to an element. Send Keys 将一系列击键发送到一个元素。 Can you replace the following two lines您可以替换以下两行吗

driver.findElement(By.xpath("//XCUIElementTypeApplication[@name=\"TBI\"]")).click();

driver.getKeyboard().sendKeys("abc");

with

MobileElement mobileElement = driver.findElement(By.xpath("//XCUIElementTypeApplication[@name=\"TBI\"]"));
mobileElement.sendKeys("abc");

Try this.尝试这个。 Worked for me:为我工作:

IWebElement currentElement = driver.SwitchTo().ActiveElement();
currentElement.SendKeys("any text");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM