简体   繁体   中英

Switching between browser tabs - 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)

The above is a code snippet of my appium tests of a website in chrome browser, which is being run on a physical device(android). There is a button on web page which opens a new tab. I have to switch between these two tabs, but I am getting this error:

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)

at this line:

self.driver.switch_to.window(window_after)

my appium server version is 1.8.1 and appium python client version is 0.28.

When I printed "window_before" and "window_after" variables the result is CDwindow-0 , CDWindow-1 respectively

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM