赞
踩
目的:学习笔记
代码:
from selenium import webdriver
br=webdriver.Chrome()#启动浏览器
br.get('https://www.baidu.com/')
apython3=br.find_element_by_xpath('//a[contains(text(),"更多")]')
link=apython3.get_attribute('href')
new_window='window.open("{}")'.format(link)#js函数,此方法适用于所有的浏览器
br.execute_script(new_window)#打开一个新窗口
print(br.current_window_handle)#当前窗口
print(br.window_handles)#所有窗口
sw=br.switch_to.window(br.window_handles[1])#切换到第二个窗口
print(br.current_window_handle)#当前窗口
结果:
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。