python+selenium自动化测试同一个浏览器如何切换到另一个页面

 

 

 

 

 某个操作点击之后形成第二个标签就可以进行下方的代码的书写

index = self.driver.current_window_handle


handles = self.driver.window_handles
current= None


for handle in handles:
if handle != index:
current= handle
self.driver.switch_to.window(current)
time.sleep(3)
#在另一个页面需要进行的操作

.......
self.driver.close()

#切换回到原来的页面
self.driver.switch_to.window(index)

posted @ 2020-10-13 20:25  陈文芝  阅读(1395)  评论(0编辑  收藏  举报