当前位置:网站首页>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)
边栏推荐
- layer.prompt
- 求职大厂被拒?腾讯高手总结了11条被拒的原因!
- 数据仓库模型分层ODS、DWD、DWM实战
- 网站加了CDN后,字体图标报错Access-Control-Allow-Origin
- 对强缓存和协商缓存的理解
- Amazing pandaverse:meta "borderless, to activate fashion attributes in the new journey of 2.0
- 优雅书写Controller(参数验证+统一异常处理)
- Adobe Premiere Basics - common video effects (cropping, black and white, clip speed, mirroring, lens halo) (XV)
- 第八届“互联网+”大赛 | 云原生赛道邀你来挑战
- SD6.22集训总结
猜你喜欢

76.二叉树的最近公共祖先

JWT登录验证

Stepping on the pit: json Parse and json stringify

Notes on spintronics - zhangshufeng

unittest单元测试框架
![报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket](/img/8a/ebad75daa581e22d50dddde49e1fac.jpg)
报错[warning] Neural network inference was performed on socket ‘RGB’, depth frame is aligned to socket

关于微服务

JWT login authentication

The table ‘table_name‘ is full 异常排查及解决方案

Selenium WebDriver的高级特性
随机推荐
How to use an oak camera as a webcam?
[daily training] 535 Encryption and decryption of tinyurl
Shell基本语法--流程控制
Anaconda安装并配置jupyter notebook远程
JDBC knowledge
Fastdfs
Using protobuf to link MySQL in unrealeengine plug-in
MySQL enterprise development specification
Mac: MySQL 66 questions, 20000 words + 50 pictures!
细说GaussDB(DWS)复杂多样的资源负载管理手段
Apache Doris basic usage summary
防汛救援便携式应急通信系统解决方案
JS text particle dynamic background
The 8th "Internet +" competition - cloud native track invites you to challenge
熊猫跑酷js小游戏代码
Redis(一)--Redis入门(1)--Redis介绍、安装与启动、常用配置
SD6.23集训总结
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
Fluent's MSH grid learning
PHP outputs all dates between two specified dates