bw = webdriver.Chrome(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe')
bw.get("http://www.baidu.com")
bw.execute_script("window.open('https://www.douban.com/')")
bw.execute_script("window.open('https://www.bilibili.com/')")
bw.execute_script("window.open('https://www.taobao.com/')")
bw.switch_to.window(bw.window_handles[3])
在调试页面切换效果的时候发现,是按handles[0] 为百度、 handles[1]为淘宝
handles[2]为b站、 handles[3]为豆瓣,的对应进行切换的。怎么和打开页面顺序也是页面排列顺序坐标不一样呢?
这个顺序不能保证,你在chrome打开新tab也会发现,不一定是按照创建的顺序排列tab的。你可以用一个字典来对应,从而切换到需要的页面,而不是参照顺序。