怎样在小程序里实现标题的更改
1446
2022-09-09
selenium - webdriver 多窗口切换 switch_to.window()
current_window_handlewindow_handlesswitch_to.window(handle)
例子:
2. 跳转到注册窗口,在注册窗口进行操作
1 from selenium import webdriver 2 import time 3 4 driver = webdriver.Chrome() 5 driver.maximize_window() 6 driver.get('7 8 search_window = driver.current_window_handle # 获取当前窗口句柄 9 time.sleep(3)10 driver.find_element_by_link_text('登录').click()11 time.sleep(3)12 driver.find_element_by_link_text('立即注册').click()13 14 all_window_handles = driver.window_handles # 获取当前所有打开窗口的句柄15 16 for handle in all_window_handles:17 if handle != search_window:18 driver.switch_to.window(handle) # 跳转到注册窗口19 driver.find_element_by_id('TANGRAM__PSP_4__userName').send_keys('jda')20 driver.find_element_by_id('TANGRAM__PSP_4__phone').send_keys('13100000000')21 driver.find_element_by_id('TANGRAM__PSP_4__password').send_keys('fda')22 time.sleep(3)23 24 for handle in all_window_handles:25 if handle == search_window:26 driver.switch_to.window(handle) # 跳转到百度首页窗口27 driver.find_element_by_id('TANGRAM__PSP_4__closeBtn').click()28 driver.find_element_by_id('kw').send_keys('zhangyang')29 driver.find_element_by_id('su').click()30 time.sleep(3)31 32
使用js,打开新的tab页面
js1 = 'window.open("= 'window.open("{}")'.format("= f'window.open("{"selenium import webdriverimport timedriver = webdriver.Chrome()driver.maximize_window()driver.implicitly_wait(10)urls = ['''url in urls: js = 'window.open("{}")'.format(url) driver.execute_script(js) driver.switch_to.window(driver.window_handles[-1]) print(driver.window_handles) print(driver.current_window_handle) print(driver.title)time.sleep(3)driver.quit()
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~