博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python+selenium自动化测试-定位方式
阅读量:6902 次
发布时间:2019-06-27

本文共 866 字,大约阅读时间需要 2 分钟。

 可用 taskkill /im chromedriver /f  命令杀掉chromedriver

import timefrom selenium import webdriverdriver = webdriver.Chrome()driver.get('http://www.baidu.com')# driver.find_element_by_link_text("新闻").click()driver.find_element_by_xpath("//*[@id='u1']/a[1]").click()driver.find_element_by_id('ww').send_keys('abcd')driver.find_element_by_id('s_btn_wr').click()time.sleep(2)# 获取当前窗口句柄main_handle = driver.current_window_handle# 定位到所有的‘abcd’搜索结果,10个eles = driver.find_elements_by_xpath('//div/h3/a')for ele in eles:    print(ele.text)    ele.click()    time.sleep(1)    # 获取所有窗口的句柄    handles = driver.window_handles    for handle in handles:        if handle != main_handle:            driver.switch_to_window(handle)            driver.close()    driver.switch_to_window(main_handle)time.sleep(3)driver.close()driver.quit()

  

转载于:https://www.cnblogs.com/jxu25/p/10963052.html

你可能感兴趣的文章
我的友情链接
查看>>
UI集成测试运行说明
查看>>
ES与Javscript,JScript,ActionScript等脚本
查看>>
断点的技巧
查看>>
mariadb配置安装
查看>>
自己做网站怎么计算带宽需求
查看>>
流镜像,端口镜像
查看>>
3月23日作业
查看>>
C语言之枚举
查看>>
我的友情链接
查看>>
程序员学习能力提升三要素
查看>>
Mysqli的批量CRUD数据
查看>>
oracle 10g升级流程
查看>>
linux下DNS服务器的实现1
查看>>
BGinfo设置记录文档
查看>>
爆款打造之中小卖家如何做到零成本选/测款?(一)
查看>>
性能监测工具 dstat
查看>>
匿名无须交互输入用户名和密码的samba配置方法(security=user)
查看>>
我的友情链接
查看>>
UTM四公子
查看>>