c# - 使用WinApp驱动在桌面任务栏中打开应用程序时如何切换应用程序
问题描述
我正在使用 Winapp 驱动程序、appium 和 c# 来自动化桌面应用程序。我的 scerios 是:我有一个应用程序,我单击打开 excel 表的按钮,该表现在显示在桌面的任务栏中。现在我想从我的桌面应用程序切换到 excel 工作表。
我无法找到相同的单一解决方案。帮助将不胜感激。
解决方案
1.) 尝试通过以下方式获取 WindowHandles():
Set<String> windowHandles = driver.getWindowHandles();
如果这组有 2 个值,那么您可以通过以下方式轻松地在两个应用程序之间切换:
driver.switchTo.window(windowHandleOfExcel);
2.) 如果集合只包含一个句柄,那么您需要为您的 excel 创建一个新的桌面会话,您可以通过以下方式执行相同操作:
//get a root driver
//all the opened application will be children of this root driver
//get the expected child driver
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("app", "Root");
WindowsDriver rootDriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);
WebElement ele = d.findElementByName("Book - Excel"); //Pass the header or title of the excel opened
String toplevel = ele.getAttribute("NativeWindowHandle");
int x = (Integer.parseInt(toplevel));
toplevel = Integer.toHexString(x);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("appTopLevelWindow", toplevel);
WindowsDriver childdriver = new WindowsDriver(new URL("http://127.0.0.1:4723"), cap);
childDriver 是指向 Excel 应用程序的驱动程序。
希望这可以帮助。
推荐阅读
- javascript - 用单击的图像替换主图像
- image - 通过使用 SVG 过滤器将噪声应用到具有透明度的图像
- python - Python edhesive 10.4
- javascript - 响应时间 childElementCount 延迟
- php - 使用 Laravel 的页面无法加载
- docker - Docker容器不断回来
- android - 如何修复 android Studio 4.1.1 中的 aapt2 错误?
- arrays - 删除和排序对象中的元素
- networking - tor 中间节点无法连接到私有 tor 权限服务器
- uml - 如何在 UML 中建模不同类型的字段和实体连接