当前位置:网站首页>Advanced features of selenium webdriver
Advanced features of selenium webdriver
2022-06-29 18:58:00 【It's Joe Joe】
Keyboard and mouse events
adopt WebDriver Of ActionChains Class implementation .



Keyboard events
adopt ActionChains class , Analog simultaneous press shift+n key .
ActionChains(driver).\
key_down(Keys.SHIFT).\
send_keys('n').\
key_up(Keys.SHIFT).perform()
Mouse events
move_to_element() You can move the cursor from the current position to the specified position .
age_field = driver.find_element_by_id("age")
ActionChains(self.driver).move_to_element(age_field).perform()
Double click operation
double_click Method implementation double click .
box = driver.find_element_by_tag_name("div")
ActionChains(driver).double_click(box).perform()
Mouse drag
adopt drag_and_drop() Implement the drag and drop operation of the mouse .
source = driver.find_element_by_id("draggable")
target = driver.find_element_by_id("droppable")
ActionChains(self.driver).drag_and_drop(source,
target). perform()
call JavaScript
WebDriver Class contains the following methods :
Screen capture


When the test script cannot find “promo_banner” Element time , The program calls save_screenshot() Method to automatically capture the screen , And save the image file name defined by us in the specified path .
try:
promo_banner_elem = driver.find_element_by_id("prom
o_banner")
self.assertEqual("Promotions", promo_banner_elem.te
xt)
except NoSuchElementException:
st = datetime.datetime.fromtimestamp(time.time()).
strftime('%Y%m%d_%H%M%S')
file_name = "main_page_missing_banner" + st + ".png
"
driver.save_screenshot(file__name)
raise
Screen Recording
Webdriver Class does not integrate screen recording api Method . So you need to use python Medium Castro library .
Castro Is based on cross platform screen recording tools Pyvnc2swf Development , Use VNC The protocol records the screen and generates SWF file .
adopt Castro, It can also realize screen recording of remote machines .
pip install Castro
from castro import Castro
class SearchProductsTest(unittest.TestCase):
def setUp(self):
self.screenCapture = Castro(filename="testSearchByCategory. swf")
self.screenCapture.start() # Start recording
# establish webdriver session, Capture page element coordinates
...
def teardown(self):
self.driver.quit()
self.screenCapture.stop() # Exit recording
Frame handling
switch_to.window() Method to get the name or handle information of the pop-up window , Switch to the pop-up frame to be operated .
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get(self.URL)
self.driver.maximize_window()
def test_popup_window(self):
driver=self.driver
parent_window_id = driver.current_window_handle
driver.switch_to.window("HelpWindow")
driver.close() # Close subwindow
driver.switch_to.window(parent_window_id) # Return to parent window
operation cookies
WebDriver Provides reading 、 Add and remove cookies Methods .
def test_store_cookie(self):
store_cookie = driver.get_cookie("store")
self.assertEqual(None, store_cookie)
select_language.select_by_visible_text("French")
store_cookie = driver.get_cookie("store")['value'] # By passing cookie Get the corresponding name cookie Value
self.assertEqual("french", store_cookie)
边栏推荐
- MySQL Enterprise Development Specification
- 保持jupyter notebook在终端关闭时的连接方法
- Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket
- curl下载示例
- Apache inlong million billion level data stream processing
- 踩坑记:JSON.parse和JSON.stringify
- Dragon canvas animation
- Hello, do you have any official website samples for MySQL CDC, PostgreSQL CDC? Give me a link to learn
- MySQL 企業級開發規範
- Failed to allocate graph: myriad device is not opened
猜你喜欢

深度学习---三好学生各成绩所占权重问题(2)
![Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
Error [warning] neural network information was performed on socket 'RGB', depth frame is aligned to socket

MariaDB的安装与配置

Machine learning 8-artificial neural network

Sword finger offer 34 Path DFS method for binary tree neutralization

Shandong University project training (VI) Click event display line chart

75. nearest common ancestor of binary search tree

RocketMQ的tag过滤和sql过滤

山东大学项目实训(七)添加导航栏选择城市

Cannot retrieve repository metadata processing records
随机推荐
JWT login authentication
svg画圆路径动画
JS text particle dynamic background
第三方工具與框架集成
Redis (I) -- getting started with redis (2) -- redis data type
Fastdfs
信息系统项目管理师---第七章项目成本管理历年考题
产品-Axure9(英文版),中继器(Repeater)实现表格内容的增删查改(CRUD)
sql server备份以及还原的命令操作
centos 7.5安装mysql 8.0.27----yum
layer. prompt
data-*属性用法
移动端测试
PHP implementation of sorting two-dimensional arrays by specified key names
Leetcode 984. String without AAA or BBB (thought of netizens)
Svg circle drawing path animation
[Nanjing University] information sharing of the first and second postgraduate entrance examinations
SD6.25集训总结
数据分析基础--预测模型
MySQL enterprise development specification