How to turn off Wifi or enable aero plane mode without swipe method


Am not able to turn on aero plane mode or turn off wifi using appium

I used below script:
NetworkConnection mobileDriver = (NetworkConnection) aDriver;
if (mobileDriver.getNetworkConnection() != ConnectionType.AIRPLANE_MODE) {
// enabling Airplane mode

744 - org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Error executing adbExec. Original error: ‘Command ‘C:\Users\TestUser\AppData\Local\Android\Sdk\platform-tools\adb.exe -P 5037 -s ce11160bd2dwqeqa3 shell am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true’ exited with code 4294967295’; Stderr: 'Security exception: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=28306, uid=2000

java.lang.SecurityException: Permission Denial: not allowed to send broadcast android.intent.action.AIRPLANE_MODE from pid=28306, uid=2000
at android.os.ShellCommand.exec(
at android.os.Binder.shellCommand(
at android.os.Binder.onTransact(
at android.os.Binder.execTransact(’; Code: ‘4294967295’ (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 7.85 seconds


Android does not support programmatic airplane mode switch since version 7.0


Please suggest me alternative solution.


Hi, I’m using this custom methods to turn of and of the connection, I’m switching off the wifi, I don’t need Airplane.
Of course you can customize to turn on Airplane mode .withAirplaneModeEnabled().
required java client 6.0.0.

public void setConnectionToOFF() {
try {
driver.setConnection(new ConnectionStateBuilder().withWiFiDisabled().build());
System.out.println("Switching OFF the connection : " + driver.getConnection());
} catch (Exception e) {
System.out.println(“Connection could not be switch OFF”);

public void setConnectionToON() {
	try {
		driver.setConnection(new ConnectionStateBuilder().withWiFiEnabled().build());
		System.out.println("Switching On the connection: " + driver.getConnection());
	} catch (Exception e) {
		System.out.println("Connection could not be switch ON");


Is this running in Oreo?


unfortunately not, you’ll get connection refused. Although the driver manage to close the WIFI :))
I’m running the tests on 6.0 so there is working.
I might suggest to do it as well. but depends on your app.
When i’m trying to run the test on 8 or 7, there is a 80% change that the test will fail. mostly the driver cannot find some elements.