码迷,mamicode.com
首页 > 其他好文 > 详细

selenium之实现多窗口切换到自己想要的窗口

时间:2019-01-18 01:00:15      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:https   import   utf-8   [1]   handle   port   expec   web   密码   

#coding=utf-8
from selenium import webdriver
import time
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome()
driver.get(‘https://www.imooc.com/user/newlogin/from_url/‘)
driver.find_element_by_name(‘email‘).send_keys(‘自己慕课网账号‘)
driver.find_element_by_name(‘password‘).send_keys(‘对应密码)
driver.find_element_by_class_name(‘moco-btn‘).click()
time.sleep(2)
driver.get(‘https://www.imooc.com/user/setbindsns‘)
driver.find_elements_by_class_name(‘inner-i-box‘)[1].find_element_by_class_name(‘moco-btn-normal‘).click()
handl_list = driver.window_handles
current_handle = driver.current_window_handle
print(handl_list)
#[1,2,3,4]
time.sleep(15)
for i in handl_list:
    if i != current_handle:
        time.sleep(2)
        driver.switch_to.window(i)
        ti = EC.title_contains("网站连接")
        if ti(driver) == True:
            break
time.sleep(5) 
driver.find_element_by_id(‘userId‘).send_keys(‘test‘)
time.sleep(5)
driver.close()

selenium之实现多窗口切换到自己想要的窗口

标签:https   import   utf-8   [1]   handle   port   expec   web   密码   

原文地址:https://www.cnblogs.com/raind/p/10285490.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!