当前位置:网站首页>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)
边栏推荐
- Us judge ruled that the former security director of Uber accused of covering up hacking must face fraud charges
- SD6.23集训总结
- 面试题 10.10. 数字流的秩
- MySQL Enterprise Development Specification
- Adobe Premiere foundation - batch material import sequence - variable speed and rewind (recall) - continuous action shot switching - subtitle requirements (13)
- About microservices
- 第三方工具與框架集成
- [Nanjing University] information sharing of the first and second postgraduate entrance examinations
- Leetcode 984. String without AAA or BBB (thought of netizens)
- Fastdfs
猜你喜欢

Shandong University project training (VII) add navigation bar to select city

How to use the oak camera on raspberry pie?

JWT登录验证

Apache Doris basic usage summary

js文本粒子动态背景

Redis(一)--Redis入门(2)--Redis数据类型

TP5 where queries whether a field in the database contains a value. Fuzzy queries are performed without the like method

Sword finger offer 34 Path DFS method for binary tree neutralization

Failed to allocate graph: myriad device is not opened

76. nearest common ancestor of binary tree
随机推荐
Know that Chuangyu has helped the energy industry in asset management and was selected into the 2021 IOT demonstration project of the Ministry of industry and information technology
Shell基本语法--流程控制
2. add customized related files to the keil5 project established by stm32cubemx
6.29模拟赛总结
第八届“互联网+”大赛 | 云原生赛道邀你来挑战
PHP implementation of sorting two-dimensional arrays by specified key names
About microservices
sql server备份以及还原的命令操作
Mac: MySQL 66 questions, 20000 words + 50 pictures!
MySQL Enterprise Development Specification
The table ‘table_ Name 'is full exception troubleshooting and solution
Shandong University project training (VIII) design rotation map entry page
压测并发数的确定
Sd6.24 summary of intensive training
保持jupyter notebook在终端关闭时的连接方法
Weibo comments on high-performance and high availability architecture design (module 5 of architecture practice camp)
How to use an oak camera as a webcam?
您好,请问mysql cdc、和postgresql cdc有官网样例吗?给个链接学习了
细说GaussDB(DWS)复杂多样的资源负载管理手段
第三方工具与框架集成