【发布时间】:2015-10-05 12:08:23
【问题描述】:
我正在使用 appium dot net 驱动程序,我想关闭/打开 wifi。请建议在 c# 中使用 appium 或 adb 命令的方法,可以发送到设备以关闭 wifi
【问题讨论】:
我正在使用 appium dot net 驱动程序,我想关闭/打开 wifi。请建议在 c# 中使用 appium 或 adb 命令的方法,可以发送到设备以关闭 wifi
【问题讨论】:
来自问题How to turn off Wifi via ADB?:
启用 Wi-Fi:
adb shell svc wifi enable
禁用 Wi-Fi:
adb shell svc wifi disable
来自问题Run Command Prompt Commands:
System.Diagnostics.Process process = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();
startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
startInfo.FileName = "cmd.exe";
startInfo.Arguments = "/C adb shell svc wifi enable/disable";
process.StartInfo = startInfo;
process.Start();
注意:我不懂C#,如有错误请指正。
【讨论】:
在 C# 中,我不确定直接方法,但你可以试试这个:
禁用 WIFI:
((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AirplaneMode;
启用 WIFI:
((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AllNetworkOn;
【讨论】:
OpenQA.Selenium.WebDriverException : An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: 'Command ''C:\\Program Files (x86)\\Android\\android-sdk\\platform-tools\\adb.exe' -P 5037 -s 19025D8359 shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true' exited with code 1'; Stderr: 'java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=29791, uid=2000