#!/usr/bin/env python
# -*- coding:utf-8 -*- from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
# <input type="submit" value="百度一下" id="su" class="btn self-btn bg s_btn">
#id
keys="工作"
delay=3
url="http://sz.ganji.com/"
driver=webdriver.Firefox() driver.get(url) #等待delay秒
driver.implicitly_wait(delay) #当前窗口句柄
cur_handle=driver.current_window_handle #获取所有句柄
driver.find_element_by_link_text(keys).click()
all_handle=driver.window_handles # #切换句柄方法1
for i in all_handle:
if i!=cur_handle:
driver.switch_to.window(i)
#
# #切换句柄方法2
driver.switch_to.window(all_handle[1])
print(driver.title) # 切回到首页窗口
driver.close()
driver.switch_to.window(cur_handle)
print(driver.title) #等待delay秒
time.sleep(delay) # # 退出当前窗口
driver.close() # 退出所有窗口
driver.quit()

Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)的更多相关文章

  1. Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )

    !/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...

  2. Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...

  3. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  4. Python3+Selenium3+webdriver学习笔记11(cookie处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...

  5. Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...

  6. Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...

  7. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  8. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  9. Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

随机推荐

  1. [51nod1035]最长的循环节

    题意:输出<=n的数中倒数循环节长度最长的那个数 解题关键:http://w3.math.sinica.edu.tw/math_media/d253/25311.pdf https://wenk ...

  2. 远程抓取win7 的用户登录时间

    protected void Page_Load(object sender, EventArgs e) { InvokeSystemPS("query user /server:192.1 ...

  3. JAVA获取本周 本月 本年 第一天和最后一天

    /** * 日期工具类 */ public class DateUtils { /** * 获取今天 * @return String * */ public static String getTod ...

  4. Git 分支管理 不使用Fast forward模式进行合并 分支管理策略

    通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...

  5. 每次移1px的无缝轮播图

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  6. 3damx平滑组注意事项

    需要在Editable Poly->面级别,选中(需要平滑的)面,然后去点平滑组或自动平滑 如果出现下图的情况,说明可能是有多余点,点没缝合 max中确认,确实是点没缝合导致

  7. 笔记-迎难而上之Java基础进阶2

    Set集合 import java.util.*; public class HashSetDemo{ public static void main(String[] args){ //Set接口的 ...

  8. swift5 正则简单使用

    /* 判断是否价格 */ let money = "100.98" let parrern = "^\\d+(\\.\\d{0,2})?$" if NSPred ...

  9. jsonpath 求和

    { "price": [ 1.0, 2.0 ] } $..price.sum() 以下表达式

  10. Luogu P1447 [NOI2010]能量采集 数论??欧拉

    刚学的欧拉反演(在最后)就用上了,挺好$qwq$ 题意:求$\sum_{i=1}^{N}\sum_{j=1}^{M}(2*gcd(i,j)-1)$ 原式 $=2*\sum_{i=1}^{N}\sum_ ...