I am using appium dot net driver and I want to switch off/on the wifi . Please suggest method in c# using appium or adb command that can be send to device to switch off wifi
Asked
Active
Viewed 1,256 times
2 Answers
0
From question How to turn off Wifi via ADB?:
Enable Wi-Fi:
adb shell svc wifi enable
Disable Wi-Fi:
adb shell svc wifi disable
From question 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();
Note: I don't know C#, so correct me if something is wrong.

Kirill
- 1,530
- 5
- 24
- 48
-1
In C#, I am not sure about direct method, but you can try this:
To Disable WIFI:
((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AirplaneMode;
To Enable WIFI:
((AndroidDriver<AppiumWebElement>)appiumDriver).ConnectionType = ConnectionType.AllNetworkOn;

Stephen Rauch
- 47,830
- 31
- 106
- 135

Ganesh Devaraj
- 39
- 4
-
1Not sure if this answer is valid anymore -- throws error `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` – CEH Oct 21 '19 at 21:14