我尝试了以下代码但显示错误消息:
driver.rotate(org.openqa.selenium.ScreenOrientation.LANDSCAPE);
Thread.sleep(5000); driver.rotate(org.openqa.selenium.ScreenOrientation.PORTRAIT);
Thread.sleep(5000);
错误讯息: -
处理命令时发生未知的服务器端错误。 (警告:服务器未提供任何堆栈跟踪信息)
答案 0 :(得分:0)
似乎有"Set the orientation, but app refused to rotate."
错误消息的解决方案。您的问题可能与应用程序依赖传感器进行旋转并且不允许用户设置它的事实有关。 “maxski”的情况至少如此:https://discuss.appium.io/t/android-set-the-orientation-but-app-refused-to-rotate/3200/3
"The problem was in Android app code. Devs should set orientation reliance to user not to censor."
答案 1 :(得分:0)
使用以下代码识别方向是否为纵向。
公共布尔Method_isCurrentOrientationPortrait(@SuppressWarnings(“ rawtypes”)AppiumDriver驱动程序){
字符串ort = driver.getOrientation()。name();
ScreenOrientation方向= ScreenOrientation.valueOf(ort);
if (orientation == ScreenOrientation.PORTRAIT) {
System.out.println("Current screen orientation is portrait");
return true;
} else {
System.out.println("Current screen orientation is Landscape");
return false;
}
}