如何在appiumpython中的两个窗口之间切换

问题描述

我正在尝试运行一个在运行时打开新窗口的测试 我的主应用程序中有一个按钮,可以打开一个名称不同的新窗口 我尝试使用:

desired_caps["app"] = 'myappname'
driver = webdriver.Remote(
        command_executor='http://127.0.0.1:4723',desired_capabilities= desired_caps)
driver.find_element_by_name("OK").click()
#after click on this a new window opens with this name,"Confirmation"
driver.switch_to_window("Confirmation")

我也尝试用另一种方式写

webdriver.switch_to.SwitchTo.window(self,"Confirmation")

有人可以帮我吗?

解决方法

我看不到您在哪里打开了新窗口。您要切换到尚未打开的窗口吗?

尝试:

driver.get('http://website.com')
,

要在Windows基本应用程序中的两个窗口之间切换,我们可以使用...

windows = self.driver.window_handles
self.driver.switch_to.window(windows[0])

通过此代码段,我们可以在彼此打开的两个窗口之间切换。 通常会在主窗口中打开“是”或“否”窗口,您可以以此切换到该窗口。