自动化测试之鼠标悬浮操作、双击、鼠标拖拽
鼠標操作。封裝在ActionChains中
-move_to_element
-double_click 雙擊
-context_click right_click 右鍵
-drag_and_drop 鼠標拖拽
-click 單擊
鼠標懸浮操作
操作–在百度頁面中找高級搜索
雖然在html中能找到高級搜索,但是并不一定在頁面中能找到高級搜索
操作步驟為,先點擊設置----再點擊高級搜索
第一種方法 — 點擊
#定位設置標簽
setting_el=driver.find_element_by_xpath(’//span[@id=“s-usersetting-top”]’)
setting_el.click()
#再定位到高級設置標簽
top_setting_el=driver.find_element_by_xpath(’//a[text()=“高級搜索”]’)
top_setting_el.click()
第二種方法 --鼠標懸停
用法基本是固定的----封裝
1、初始化一個action_chains對象
action=ActionChains(driver)
2、找到要懸浮的元素,
setting_el=driver.find_element_by_xpath(’//span[@id=“s-usersetting-top”]’) -----> 設置
3、調用鼠標操作的函數,傳入move_to_element()函數中
action.move_to_element(setting_el)
4、要讓動作生效的話,必須加上perform
action.move_to_element(setting_el).perform()
5、再定位到高級設置標簽
top_setting_el=driver.find_element_by_xpath(’//a[text()=“高級搜索”]’)
top_setting_el.click()
封裝:
def move_to(locator):action=ActionChains(driver)action.move_to_element(settings_el).perform() move_to(setting_el=driver.find_element_by_xpath('//span[@id="s-usersetting-top"]'))封裝成線性等待
def move_to(locator):action=ActionChains(driver)wait=WebDriverWait(driver,20).wait.until(expected_conditions.visibility_of_element_located(loactor)action.move_to_element(el).perform()move_to(loactor=('xpath','//span[@id="s-usersetting-top"]'))雙擊:double_click
def double_click(el)action=ActionChains(driver)action.double_click(el)action.perform() double_click(el)鼠標拖拽:drag_and_drop
def drag_and_drop(el1,el2)action=ActionChains(driver)action.drag_and_drop(el1,el2)action.proform() drag_and_drop(el1,el2) 《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的自动化测试之鼠标悬浮操作、双击、鼠标拖拽的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自动化测试之alert弹窗的切换
- 下一篇: 自动化测试之键盘操作和select操作