selenium + python 基础
来源:互联网 发布:股票抢单软件 编辑:程序博客网 时间:2024/06/03 12:53
By类
引入模块from selenium.webdriver.common.by import By
driver.find_element(By.ID,”id”):相对于driver.find_element_by_id(“id”)这种方式,修改的时候更加的灵活,方便
用法和driver.find_element_by_xx 的方式大致相同
#登录driver.find_element(By.NAME,"username").send_keys("admin")driver.find_element(By.NAME,"password").send_keys("a123456789")driver.find_element(By.CLASS_NAME,"button").click()
frame webDriver只能在一个页面对其上的元素进行识别和定位,所以如果涉及到其他内嵌页面,就需要跳转到内嵌页面才能对内嵌页面上的元素进行识别和定位
跳转方法:switch_to.frame()
跳转到指定的frame
driver.switch_to.frame(0)
通过索引定位
driver.switch_to.frame(“id”)
通过id定位
driver.switch_to.frame(“name”)
通过name属性定位
driver.switch_to.frame(driver.find_element(By.name,”name”))
通过webElement对象来定位
跳转到上一个frame
driver.switch_to.parent_frame()
跳转到初始frame
driver.switch_to.default_content()
相关js代码
window.frames["header-frame"].document.querySelectorAll("a[href$='logout']")
查询frame下是否含有满足条件的a标签
document.querySelectorAll("frame[src*='index.php?act=top']")
查询含有该属性的
framede的名称
#选择子页面driver.switch_to.frame("main-frame")driver.find_element(By.LINK_TEXT,"待发货订单:").click()#跳到父页面driver.switch_to.parent_frame()#选择子页面driver.switch_to.frame("header-frame")#退出driver.find_element(By.CSS_SELECTOR,"a[href*='privilege.php?act=logout']").click()
窗口切换:一个浏览器可以打开多个窗口,但是webDriver只能对一个窗口元素进行操作,若要操作其他窗口,则需要进行跳转(同frame)
handles = driver.window_handles #返回值为list集合,故可以通过循环和下标的方式操作
跳转:driver.switch_to.window(handles[0])
鼠标事件
引入模块 from selenium.webdriver import ActionChains
用法:
a. 定位到元素 locate = driver.find(By.ID,’id’)
b. 实现鼠标事件 ActionChains(driver).move_to_element(locate).perform()
#鼠标右键# loc = driver.find_element(By.ID,"kw")# ActionChains(driver).context_click(loc).perform()#鼠标悬停locx = driver.find_element(By.PARTIAL_LINK_TEXT,'家用电器')ActionChains(driver).move_to_element(locx).perform()
- Python安装基础+selenium
- selenium + python 基础
- Selenium自动化测试Python二:WebDriver基础
- 基于Python+selenium的自动化测试基础
- python+selenium第二节课(python基础)
- Selenium基础
- Selenium python
- python selenium
- python+selenium
- python + selenium
- Python Selenium
- python selenium
- Python selenium
- python+selenium
- selenium-python
- Python selenium
- Python+selenium
- Python+selenium
- reduce函数python
- 爬虫编码问题
- 循环的总结
- Xfce安装与移植
- 关于c++中的scanf函数中的一些不易发现的注意点
- selenium + python 基础
- JS函数
- 指数循环节 处理A^B 问题 Super A^B mod C + Calculation
- [STL]set实用用法
- HDU-1213 How Many Tables
- hdu 6058 并查集
- vector用法
- CTF实验吧-忘记密码了【vim编辑器备份文件】
- 通过Flow simulations找到机箱散热设计最佳方案