当前位置:网站首页>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)
边栏推荐
- centos 7.5安装mysql 8.0.27----yum
- PostGIS generate graphic cut
- JS converts seconds to "2h30min50s" format
- 535. encryption and decryption of tinyurl / Jianzhi offer II 103 Minimum number of coins
- These advantages of the Institute are really fragrant! The landing rate is still very high!
- The 8th "Internet +" competition - cloud native track invites you to challenge
- 关于微服务
- js将秒转换成“2h30min50s”的格式
- 金鱼哥RHCA回忆录:DO447构建高级作业工作流--创建工作流作业模板并启动工作流作业
- Intégration d'outils et de cadres tiers
猜你喜欢

JWT login authentication

如何使用物联网低代码平台进行服务管理?

深度学习---三好学生各成绩所占权重问题(2)

Leetcode 984. String without AAA or BBB (thought of netizens)

sql server备份以及还原的命令操作

Using protobuf to link MySQL in unrealeengine plug-in

网站加了CDN后,字体图标报错Access-Control-Allow-Origin

Redis (I) -- getting started with redis (2) -- redis data type

CentOS 7.5 install MySQL 8.0.27---yum

龙canvas动画
随机推荐
MariaDB的安装与配置
Machine learning 8-artificial neural network
PHP implementation of sorting two-dimensional arrays by specified key names
面霸篇:MySQL六十六问,两万字+五十图详解!
压测并发数的确定
Sd6.24 summary of intensive training
Redis(一)--Redis入门(1)--Redis介绍、安装与启动、常用配置
TP5 where queries whether a field in the database contains a value. Fuzzy queries are performed without the like method
JS converts seconds to "2h30min50s" format
如何使用物联网低代码平台进行服务管理?
CentOS 7.5 install MySQL 8.0.27---yum
sql server备份以及还原的命令操作
Basis of data analysis -- prediction model
Stepping on the pit: json Parse and json stringify
Fastdfs
Cannot retrieve repository metadata 处理记录
山东大学项目实训(七)添加导航栏选择城市
postgis 生成 图形切割
2022.6.29-----leetcode.535
Us judge ruled that the former security director of Uber accused of covering up hacking must face fraud charges