鼠标操作。封装在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,el):
action=ActionChains(driver)
wait=WebDriverWait(driver,20).
wait.until(expected_conditions.visibility_of_element_located(loactor)
action.move_to_element(el).perform()
loactor=('xpath','//span[@id="s-usersetting-top"]')
top_setting_el=driver.find_element_by_xpath('//a[text()="高级搜索"]')
move_to(loactor,top_setting_el)
双击: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)
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/74137.html