在浏览器标签之间切换-Appium

时间:2018-10-30 10:34:25

标签: python-3.x appium

    # get current window handle
    window_before = self.driver.window_handles[0]

    # click on a button which opens a new tab
    self.driver.find_element(*EditLocators.preview_button).click()

    # wait for new tab to open
    self.wait_for_new_tab()

    # get the new tab's window handle
    window_after = self.driver.window_handles[1]

    # switch to new tab
    self.driver.switch_to.window(window_after)

    "do some actions in new tab"

    # close that new tab
    self.driver.close()

    # switch back to original tab
    self.driver.switch_to.window(window_before)

以上是我在Chrome浏览器中对网站进行Appium测试的代码段,该代码段正在物理设备(android)上运行。网页上有一个按钮,可打开一个新选项卡。我必须在这两个选项卡之间切换,但出现此错误:

selenium.common.exceptions.WebDriverException: Message: unknown error: 'name' must be a string
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.38.552522 
(437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 4.15.0-38-generic x86_64)

在此行:

self.driver.switch_to.window(window_after)

我的appium服务器版本为1.8.1,appium python客户端版本为0.28。

当我打印“ window_before”和“ window_after”变量时,结果分别是CDwindow-0,CDWindow-1

1 个答案:

答案 0 :(得分:0)

将appium服务器从1.8.1更新到1.9.1解决了问题