首页 > 编程语言 > 详细

python3-selenium-UI自动化入门二

时间:2019-08-26 16:09:27      阅读:114      评论:0      收藏:0      [点我收藏+]

###

接上一篇

###

一、消息窗

#切换到页面的消息窗

a = driver.switch_to_alert

a.text#消息窗文本

a.accept()#相当于点击“确定”

a.dismiss()#相当于点击“取消”

 

二、切换页面框架

例如

baidu = driver.find_element_by_css_selector(‘iframe#id‘)#先定位要切换的框架

driver.switch_to.frame(baidu)#切换

 

#切换回上一级框架

driver.switch_to.parent_frame()

 

#切换到最外层框架

driver.switch_to.default_content()

 

三、切换浏览器窗口

#获得打开的所有的窗口句柄

window = driver.window_handles

 

#切换到当前最新打开的窗口

driver.switch_to.window(window[-1])

 

四、鼠标操作

from selenium.webdriver.common.action_chains import ActionChains

1、悬停

#先定义一个实例

action = ActionChains(driver)

#添加一个事件,el为定位好的元素

action.move_to_element(el)

#执行添加好的事件

action,perform()

 

2、左键按住不放

action = ActionChains(driver)

#el元素按住3s,然后释放

action.click_and_hold(el).press(3).release().perform()

 

3、右键点击

action = ActionChains(driver)

#action.context_click(el).perform()

 

4、拖拽

action = ActionChains(driver)

#把元素el拖到那个坐标上

action.drag_and_drop_by_offset(el,500,600).perform()

 

 

四、js点击元素

driver.execute_script("arguments[0].click();",el)

 

python3-selenium-UI自动化入门二

原文:https://www.cnblogs.com/Appleli/p/11412637.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!