[英]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). 上面是我在Chrome浏览器中对网站进行Appium测试的代码段,该代码段正在物理设备(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. 我的appium服务器版本是1.8.1,appium python客户端版本是0.28。
When I printed "window_before" and "window_after" variables the result is CDwindow-0 , CDWindow-1 respectively 当我打印“ window_before”和“ window_after”变量时,结果分别是CDwindow-0,CDWindow-1
将appium服务器从1.8.1更新到1.9.1解决了该问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.