#!/usr/bin/env python
# -*- coding:utf-8 -*- from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains import time,os # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
# <input type="submit" value="百度一下" id="su" class="btn self-btn bg s_btn">
#id
keys="selenium自动化"
delay=3
url="https://www.baidu.com/"
driver=webdriver.Firefox() driver.get(url) #等待delay秒
driver.implicitly_wait(delay) #输入字符串
driver.find_element_by_id("kw").send_keys(keys) #清空输入的内容
driver.find_element_by_id("kw").clear() #鼠标左键点击
driver.find_element_by_id("su").click() driver.find_element_by_id("kw").send_keys(keys) #模拟回车提交表单
driver.find_element_by_id("kw").submit() driver.find_element_by_id("kw").send_keys(Keys.ENTER) #复制 粘贴 全选 剪切 制表键 f11~f12
driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'c') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'v') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'a') driver.find_element_by_id("kw").send_keys(keys,Keys.CONTROL,'x') driver.find_element_by_id("kw").send_keys(Keys.TAB) driver.find_element_by_id("kw").send_keys(Keys.F1) #执行ActionChains中的所有行为
source=driver.find_element_by_link_text("设置")
target=driver.find_element_by_link_text("新闻") # 鼠标悬停
ActionChains(driver).move_to_element(source).perform() # 右击鼠标
ActionChains(driver).context_click(source).perform() # 双击鼠标
ActionChains(driver).double_click(source).perform() #鼠标移动到另一个位置
ActionChains(driver).drag_and_drop(source,target).perform() # 鼠标左键
ActionChains(driver).click_and_hold(source).perform() #等待delay秒
time.sleep(delay) driver.quit()

Python3+Selenium3+webdriver学习笔记5(模拟常用键盘和鼠标事件)的更多相关文章

  1. Python3+Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )

    !/usr/bin/env python -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记14(等待判断 鼠标事件 )'''from selenium im ...

  2. Python3+Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记13(js操作应用:弹出框无效如何处理)'''from sel ...

  3. Python3+Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记12(js操作应用:滚动条 日历 内嵌div)'''from ...

  4. Python3+Selenium3+webdriver学习笔记11(cookie处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记11(cookie处理)'''from selenium im ...

  5. Python3+Selenium3+webdriver学习笔记10(元素属性、页面源码)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记10(元素属性.页面源码)'''from selenium i ...

  6. Python3+Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记9(发送富文本信息及上传文件处理)'''from seleni ...

  7. Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*-'''Selenium3+webdriver学习笔记8(单选.复选框.弹窗处理)''' from selenium ...

  8. Python3+Selenium3+webdriver学习笔记7(选择多链接的结果、iframe、下拉框)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

  9. Python3+Selenium3+webdriver学习笔记6(多窗口切换处理)

    #!/usr/bin/env python# -*- coding:utf-8 -*- from selenium import webdriverfrom selenium.webdriver.co ...

随机推荐

  1. There&nbsp;is&nbsp;no&nbsp;resul…

    There is no result type defined for type 'json' mapped with name 'success'. 这个错误是json初学者很容易遇到的错误:现在把 ...

  2. 利用msfvenom制作木马程序(你可以得到她的一切)

    实验环境: 虚拟机:kali  (攻击机)          192.168.1.2 虚拟机:windwos 2003 (靶机)   192.168.1.100 1. 制作木马 说明: -p payl ...

  3. [Makefile] 递归编译的Makefile的实现

    转自:http://www.linuxidc.com/Linux/2017-01/139702.htm 最近写了一个递归Makefile,目的是既可以实现子模块的单独编译,也可以不做任何修改就和整个程 ...

  4. You have configured this virtual machine to use a 64-bit guest operating system. However, 64-bit

    vm虚拟机 问题:You have configured this virtual machine to use a 64-bit guest operating system.  However, ...

  5. python寻找小于给定值的最大质数

    # -*- utf-8 -*- # @Time: 2019-04-16 # @ Author: chen def prime(self, value): """判断是否为 ...

  6. IT兄弟连 Java语法教程 Java的发展历程

    只有少数几种编程语言对程序设计带来过根本性的影响.其中,Java的影响由于迅速和广泛而格外突出.可以毫不夸张的说,1995年Sun公司发布的Java1.0给计算机程序设计领域带来了一场变革.这场变革迅 ...

  7. wamp的HTTPS配置

    1.需要去申请ssl证书 2.打开wamp的apache的配置文件:httpd.conf 找到 LoadModule ssl_module modules/mod_ssl.so Include con ...

  8. 洛谷P4568 飞行路线

    题目描述 \(Alice\)和\(Bob\)现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在\(n\)个城市设有业务,设这些城市分别标记为\(0\)到\(n−1\),一共有\(m\ ...

  9. mysql5.7日志时间戳(log_timestmaps)与系统时间不一致问题以及日志报Got an error reading communication packets情况分析

    一.mysql安装后error_log日志时间戳默认为UTC(如下图),因此会造成与系统时间不一致,与北京时间相差8个小时. 解决errro_logs时间戳与linux系统时间不一致问题 step1: ...

  10. C# string.Empty

    在C#中,如果赋值一个字符串为空白字符串,我们一般会用“”的形式对字符串进行赋值操作,其实在C#的字符串类String类中,有个专门的常量string.Empty来代表空字符串,可直接在赋值的时候使用 ...