Change Device Orientation

You can change the device orientation by using the deviceOrientation capability.

Capability Description Expected values
deviceOrientation Set the screen orientation of the mobile device A string. Default is portrait.

portrait if you want the device to be in portrait mode, landscape otherwise.

For example, refer to the sample of setting device orientation to landscape:

// Change device orientation to landscape

DesiredCapabilities caps = new DesiredCapabilities();
caps.setCapability("deviceOrientation", "landscape");
// Change device orientation to landscape

var capabilities = {
 "deviceOrientation" : "landscape"
}
// Change device orientation to landscape

// For Chrome browser
ChromeOptions capability = new ChromeOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape", true);

// For Edge browser
EdgeOptions capability = new EdgeOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape");

// For IE browser
InternetExplorerOptions capability = new InternetExplorerOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape", true);

// For Firefox browser
FirefoxOptions capability = new FirefoxOptions();
capability.AddAdditionalCapability("deviceOrientation", "landscape", true);
# Change device orientation to landscape

$caps = array(
 "deviceOrientation" => "landscape"
);
# Change device orientation to landscape

capabilities = {
 "deviceOrientation" : "landscape"
}
# Change device orientation to landscape

caps = Selenium::WebDriver::Remote::Capabilities.new
caps["deviceOrientation"] = "landscape"
# Change device orientation to landscape

my $capabilities = {
 "deviceOrientation" => "landscape"
}
Note: Changing the orientation of your mobile device can be done only before test execution starts, using a capability. The orientation cannot be changed in the middle of the test script.

Following is the example of the device orientation in landscape mode: landscape

If deviceOrientation capability is not set, the test will run in portrait mode as shown in the following figure:

portrait

We're sorry to hear that. Please share your feedback so we can do better






Contact our Support team for immediate help while we work on improving our docs.

We're continuously improving our docs. We'd love to know what you liked





Thank you for your valuable feedback