13

我正在尝试使用 appium 和以下代码打开控制中心:

    int halfWidth = driver.manage().window().getSize().width / 2;
    int screenHeight = driver.manage().window().getSize().height;
    driver.swipe(halfWidth, screenHeight-5, halfWidth, screenHeight-300, 500);  // driver is instance of IOSDriver

该应用程序无需打开控制中心,而是简单地从底部向上绘制屏幕(使用坐标输入)。任何人都知道如何使用 appium 和滑动(或任何其他方式)打开控制中心?

谢谢,查理

4

7 回答 7

5

我们做得到。我在 Appium 1.4.13 中尝试过,我可以更改设置。

我使用下面的代码来更改我的 iPadAir2 中的设置。

int height = driver.findElementByClassName("UIAWindow").getSize().getHeight();
int width = driver.findElementByClassName("UIAWindow").getSize().getWidth();
driver.swipe(width-100, height, width-100, height-200, 500);
driver.findElementByAccessibilityId("Wi-Fi").click();
于 2016-02-01T06:59:30.843 回答
1

Appium 1.6.5,您可以使用滑动方法,下面是我的 Python 代码:

window_size = self.driver.get_window_size()  # this returns dictionary
el = self.driver.find_element(*self.configuration.CommonScreen.WEB_VIEW)
action = TouchAction(self.driver)
start_x = window_size["width"] * 0.5
start_y = window_size["height"]
end_x = window_size["width"] * 0.5
end_y = window_size["height"] * 0.5
action.press(el, start_x, start_y).wait(100).move_to(el, end_x, end_y).release().perform() 
于 2017-10-25T15:31:01.123 回答
0

这个想法是模拟您用来在相应 iOS 设备上打开控制中心的滑动操作。我的设备是 iPhone 11,所以它从右上角(凹槽的右侧)向下滑动。我的代码是从位置(x,y)(80%宽度,0)滑动到(80%宽度,50%高度)

    Dimension size = getScreenSize();

    int x = (size.getWidth() / 5) * 4;
    int startY = 0;
    int endY = size.getHeight() / 2;

    new TouchAction(driver).press(PointOption.point(x, startY))
            .waitAction(WaitOptions.waitOptions(Duration.ofSeconds(1)))
            .moveTo(PointOption.point(x, endY))
            .release().perform();
于 2020-08-10T08:38:43.387 回答
0

我可以使用适用于 iOS 的 Appium 1.6.4-beta 关闭 Wifi 或打开飞行模式

从屏幕底部向上滑动 点击继续链接 点击 Wifi 或 Airplane 按钮 从屏幕中间向下滑动

但这似乎在模拟器中没有做任何事情。我实际上必须关闭我的计算机互联网连接才能禁用模拟器上的互联网。

@iOSFindBy(xpath = "//XCUIElementTypeSwitch[@name='Wi-Fi']")
private MobileElement WIFI_MODE_BUTTON;

public void disableWifi()  {
    openToolBarMenu();
    //if wifi is on/true then turn it off
   if (WIFI_MODE_BUTTON.getAttribute("value") == "true" ) {
       Autoscope.tap(WIFI_MODE_BUTTON);
   }
    closeToolBarMenu();
}


@iOSFindBy(xpath = "//XCUIElementTypeButton[@name='Continue']")
private MobileElement CONTINUE_BUTTON; //continue button on control center

public void openToolBarMenu() {
    Autoscope.scrollFromBottomOfScreen();
    if (Autoscope.isElementDisplayed(CONTINUE_BUTTON)) {
        Autoscope.tap(CONTINUE_BUTTON);
    }
}


static public void scrollFromBottomOfScreen() {
    TouchAction touchAction = new TouchAction(autoscopeDriver);

    int xStartPoint = Math.round(pixelWidth() / 2);
    int yStartPoint = pixelHeight();
    int yEndPoint = 0 - yStartPoint;
    touchAction.press(xStartPoint, yStartPoint).moveTo(0, yEndPoint).release().perform();
}
于 2017-05-01T18:33:00.167 回答
0

此代码将有助于调出控制中心,当您在应用程序中时,您可以执行控制中心中可用的所有操作

new TouchAction(DriverConfig.getInstance().getDriver()).press(point(250, 735)).waitAction(waitOptions(Duration.ofSeconds(3))).moveTo(point(250, -460)).release()
                        .perform();
于 2019-07-29T10:10:53.160 回答
0

C#:iOS 13.x

//Opening control center

var size = Driver.Manage().Window.Size;

var height = size.Height;

var width = size.Width;

var touchAction = new TouchAction(Driver);

touchAction.Press(width - 100, height).Wait(1000).MoveTo(width - 100, height - 200).Release().Perform();

//Clicking the WiFi button

Driver.FindElementByAccessibilityId("wifi-button").Click();

//Checking if WiFi enabled or not

var myElement = Driver.FindElementByAccessibilityId("wifi-button");

var result = myElement.GetAttribute("label");

if(!result.Contains("Wi-Fi, Not Connected") && !result.Equals("Wi-Fi"))
{
    // WiFi connected
}
else
{
    // WiFi Not connected
}
于 2020-03-11T12:44:20.620 回答
-1

好的,经过大量调查,在我看来这是不可能的。如果你真的需要这个功能,那么我认为像茄子这样的工具可能是合适的。

于 2015-07-07T21:31:10.823 回答