使用Appium处理iOS 11.1中的文件上载提示

时间:2017-11-28 19:00:58

标签: ios upload appium

我正在尝试使用Appium自动上传文件。下面是我正在使用的代码(Java):

public class DownloadLocal {
public static void main(String[] args) throws MalformedURLException, InterruptedException {
    DesiredCapabilities caps = new DesiredCapabilities();
    caps.setCapability(MobileCapabilityType.BROWSER_NAME, "Safari");
    caps.setCapability(MobileCapabilityType.PLATFORM_VERSION, "11.1");
    caps.setCapability(MobileCapabilityType.PLATFORM_NAME, "iOS");
    caps.setCapability("nativeWebTap",true);
    caps.setCapability(MobileCapabilityType.DEVICE_NAME, "iPhone 7");
    caps.setCapability(MobileCapabilityType.AUTOMATION_NAME, "Appium");
    IOSDriver driver = new IOSDriver(new URL("http://127.0.0.1:4723/wd/hub"), caps);
    driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    //Accessing files.com
    driver.get("http://files.com/");

    JavascriptExecutor js = (JavascriptExecutor) driver;

    try{
        driver.findElement(By.xpath("//*[@name='file_0']")).click();
        //Sleep to wait for upload prompt to appear
        Thread.sleep(3000);
    }catch (Exception e){
        e.printStackTrace();
    }
    //Checking if the prompt is creating an additional handle
    Set<String> contexts2= driver.getContextHandles();
    System.out.println(contexts2);
    try {
        int h=driver.manage().window().getSize().getHeight();
        int w=driver.manage().window().getSize().getWidth();
        Map<String, Object> params = new HashMap<>();
        System.out.println("x"+h);
        System.out.println("y"+w);
        params.put("x", 100);
        params.put("y", w/2);
        Thread.sleep(2000);
        js.executeScript("mobile: tap", params);

        //new TouchAction(driver).press(50,w/2).waitAction(Duration.ofSeconds(10)).release().perform();
    }catch (Exception e){
        e.printStackTrace();
    }
    driver.quit();
}
}

代码打开文件上传提示,但是,我无法使用Appium单击它。我尝试过使用点按手势。此外,尝试使用TouchAction类和默认警报功能。但是,我无法成功点击上传选项。 enter image description here

我不打算使用像Robot或Sikuli这样的选项,因为我可能会在托管在远程机器上的appium服务器上运行测试。

0 个答案:

没有答案