简体   繁体   中英

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. When I start appium server and start session, the app will open in the device. 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.

Tried getKeyboard() before sendkeys(). 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.

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. 'key' is given instead for action with id 'keyboard'}

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

Send Keys sends a sequence of key strokes to an element. 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");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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