14.Selenium2 自动化测试实战-基于Python语言-多窗口切换
来源:互联网 发布:统计局报表怎么填数据 编辑:程序博客网 时间:2024/05/21 18:34
Webdriver提供了switch_to.window()方法,可以实现在不同的窗口之间切换。
'''Author: lxtDate: 2017/03/29Method: * switch_to.window() 切换窗口 * current_window_handle 获得当前窗口的句柄 * window_handles:返回所有窗口的句柄到当前会话'''from selenium import webdriverimport timedriver =webdriver.Chrome()driver.implicitly_wait(10)driver.get("http://www.baidu.com")#获得百度搜索窗口句柄sreach_windows =driver.current_window_handledriver.find_element_by_link_text("登录").click()driver.find_element_by_link_text("立即注册").click()#获得当前所有打开的窗口的句柄all_handles=driver.window_handles#进入注册窗口for handle in all_handles: if handle !=sreach_windows: driver.switch_to.window(handle) print('now register window!') driver.find_element_by_name("userName").send_keys('username') driver.find_element_by_name("phone").send_keys('phone') time.sleep(2) # …… driver.close()#回到搜索窗口'''for handle in all_handles: if handle ==sreach_windows:'''driver.switch_to.window(sreach_windows)print("now sreach window!")time.sleep(10)driver.find_element_by_id('TANGRAM__PSP_2__closeBtn').click()driver.find_element_by_id("kw").send_keys("selenium")driver.find_element_by_id("su").click()time.sleep(2)#driver.quit()
0 0
- 14.Selenium2 自动化测试实战-基于Python语言-多窗口切换
- 13.Selenium2 自动化测试实战-基于Python语言-多表单切换
- 3.Selenium2 自动化测试实战-基于Python语言-模块调用
- 9.Selenium2 自动化测试实战-基于Python语言-键盘事件
- 10.Selenium2 自动化测试实战-基于Python语言-显示等待
- 16.Selenium2 自动化测试实战-基于Python语言-上传文件
- 17.Selenium2 自动化测试实战-基于Python语言-操作cookie
- 20.Selenium2 自动化测试实战-基于Python语言-函数
- 1.Selenium2 自动化测试实战-基于Python语言-设置窗口大小、调用JS调整滚动条、截取图片
- 15.Selenium2 自动化测试实战-基于Python语言-警告框处理
- 2.Selenium2 自动化测试实战-基于Python语言-类和方法
- 4. Selenium2 自动化测试实战-基于Python语言-跨目录模块调用
- 5.Selenium2 自动化测试实战-基于Python语言-控制浏览器后退、前进
- 6.Selenium2 自动化测试实战-基于Python语言-126邮箱登陆、获得验证信息
- 7.Selenium2 自动化测试实战-基于Python语言-WebElement接口1
- 8.Selenium2 自动化测试实战-基于Python语言-WebElement接口2
- 11.Selenium2 自动化测试实战-基于Python语言-隐式等待
- 12.Selenium2 自动化测试实战-基于Python语言-定位一组元素
- pg学习_数据更新
- 灰度直方图及直方图均衡化
- 单例模式的八种写法比较
- Dlib 实现人脸的68点检测
- 老哥稳,如何优雅的解决SSD的写入放大问题
- 14.Selenium2 自动化测试实战-基于Python语言-多窗口切换
- 1.3 Go 命令
- Python的创建型设计模式之建造者模式
- Hive SQL优化
- 2016年大数据80篇爆款文章:这一年你追过的那些技术
- .net项目技术选型总结
- 欢迎使用CSDN-markdown编辑器
- 用Oracle的函数,判断点是否在多边形内
- for update 数据库锁机制(mysql下测试)