昨天是简单的操作、之后是复杂的操作

首先是鼠标事件

AcationChains类  鼠标操作的常用方法:

右击            context_click()  

双击            double_click()  

拖动                drag_and_drop()  

鼠标悬停在一个元素上        move_to_element()  

按下鼠标左键在一个元素上    click_and_hold()

优先介绍这个是因为有些页面的元素是隐藏的、要通过鼠标悬停才显示

这里举的例子就是博客园的、代码如下:

 1 #!/usr/bin/env python
 2 # -*- coding: utf_8 -*-
 3 
 4 from learn_webdriver import Webdriver
 5 from selenium import webdriver
 6 from selenium.webdriver.common.action_chains import ActionChains
 7 from time import sleep
 8 
 9 browser_chrome = webdriver.Chrome(Webdriver.chrome())
10 browser_chrome.get("http://www.cnblogs.com/")
11 
12 sleep(2)
13 ActionChains(browser_chrome).move_to_element(browser_chrome.find_element_by_xpath(".//li[@id='cate_item_2']")).perform()
14 # 鼠标悬停在左侧“编程语言”导航栏上
15 browser_chrome.find_element_by_xpath(".//a[@href='/cate/python/']").click()
16 sleep(2)
17 browser_chrome.quit()

 

相关文章:

  • 2021-07-04
  • 2021-08-28
  • 2021-06-06
  • 2022-12-23
  • 2022-12-23
  • 2022-03-04
  • 2021-11-15
  • 2021-05-13
猜你喜欢
  • 2022-12-23
  • 2021-06-18
  • 2021-09-07
  • 2022-12-23
  • 2022-12-23
  • 2021-03-31
相关资源
相似解决方案