python-web自动化-键盘操作
selenium提供了较为完整的键盘操作
引入 from selenium.webdriver.common.keys import Keys
使用键盘操作时,需要借助send_keys()来模拟操作。
Key.CONTROL就是我们键盘上的Ctrl键
常用组合键:
send_keys(Key.CONTROL,'a') #全选(Ctrl+A)
send_keys(Key.CONTROL,'c') #复制(Ctrl+C)
send_keys(Key.CONTROL,'x') #剪切(Ctrl+X)
send_keys(Key.CONTROL,'v') #粘贴(Ctrl+V)
注意:send_keys有两个参数
常用的非组合键:
回车键 Keys.ENTER
删除键 Keys.BACK_SPACE
空格键 Keys.SPACE
制表键 Keys.TAB
回退键 Keys.ESCAPE
刷新键 Keys.F5
百度页面检索框输入文字并回车操作:
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By driver = webdriver.Chrome()#打开Chrome浏览器
driver.get('https://www.baidu.com/')#打开百度 WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,'//input[@id="kw"]')))
driver.find_element_by_xpath('//input[@id="kw"]').send_keys('许嵩',Keys.ENTER) #输入文本并回车操作
python-web自动化-键盘操作的更多相关文章
- Web自动化 - 选择操作元素 2
文章转自 白月黑羽教Python 前面我们看到了根据 id.class属性.tag名 选择元素. 如果我们要选择的 元素 没有id.class 属性, 这时候我们通常可以通过 CSS selector ...
- 【Python web自动化】之读取配置文件参数,利用cookie返回值进行跳过验证码进行登录操作
当进行Python的Web自动化时,会涉及到验证码问题,该如何跳过执行呢,下面请看代码: 1.首先新建配置文件*.ini格式 config.ini [db] #基础地址: baseurl = http ...
- python - web自动化测试 - 元素操作 - 鼠标键盘
# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: 鼠标操作.py @ide: PyCharm Community Edi ...
- python + web自动化,点击不生效,提示“selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (117, 674)”
前言: 在做web自动化时,遇到一个缩放了浏览器比例的操作,从100%缩小到80%,再进行点击的时候,弹出报错信息,无法点击 selenium.common.exceptions.ElementCli ...
- Selenium基于Python web自动化基础一 -- 基础汇总及简单操作
Selenium是UI层WEB端的自动化测试框架,也是目前市面上比较流行的自动化测试框架. ui层自动化测试本质是什么?模拟用户的真实操作行为. 基础汇总: 导入所需要的模块 from seleniu ...
- Web自动化 - 选择操作元素 1
文章转自 白月黑羽教Python 所有的 UI (用户界面)操作 的自动化,都需要选择界面元素. 选择界面元素就是:先让程序能找到你要操作的界面元素. 先找到元素,才能操作元素. 选择元素的方法 程序 ...
- python selenium鼠标键盘操作(ActionChains)
用selenium做自动化,有时候会遇到需要模拟鼠标操作才能进行的情况,比如单击.双击.点击鼠标右键.拖拽等等.而selenium给我们提供了一个类来处理这类事件--ActionChains sele ...
- python模拟鼠标键盘操作 GhostMouse tinytask 调用外部脚本或程序 autopy右键另存为
0.关键实现:程序窗口前置 python 通过js控制滚动条拉取全文 通过psutil获取pid窗口句柄,通过win32gui使程序窗口前置 通过pyauto实现右键菜单和另存为操作 1.参考 aut ...
- python - web自动化测试 - 元素操作 - 窗口切换
# -*- coding:utf-8 -*- ''' @project: web学习 @author: Jimmy @file: 元素操作-切换.py @ide: PyCharm Community ...
随机推荐
- .Net中World转PDF
using System;using System.Collections.Generic;using System.Linq;using System.Web;using Aspose.Words; ...
- 存在一个足够大的二维数组,每个数组中的值都是整数,使用javascript如何实现按每个数组中的平均值,从大到小排序这个二维数组?
这是牛客网上的一道题~ 题意:对数组排序,顺序是按照数组的平均值,即按照一个元素和平均值相减的绝对值的大小来排序...本例按这个绝对值递增排序 解题思想:先求出这个数组的平均值,如果 a<b,那 ...
- day11.3分页操作divmod
# 分页显示 divmod(被除数,除数) INFO_LIST = [] for i in range(836): template = "第%s天,笨笨先僧 always be there ...
- p132程序代码解析
1. long before = System.currentTimeMillis(); ...... long after = System.currentTimeMillis(); 解析:该两句 ...
- EXCEL日期格式要双击一下单元格才变正确格式
今天遇到标题问题,问度娘后看到一个大神的解答,特此记录整理. 步骤1:在excel中把文本格式日期改为想要的日期格式 步骤2:在旁边空格中输入1,并设置成日期格式,变成1900/1/1: 步骤3:复制 ...
- python 和python-m 的区别
首先在python自带的,help命令中,可以看到,官方的说明是:-m mod : run library module as a script (terminates option list) 意思 ...
- Visual Studio Code create the aps.net core project(Visual Studio Code 创建asp.net core项目)
Install the C# plug-in as shown below: Perfom the dotnet new --help command as shown below: Enter a ...
- shell生成随机字符串
#!/bin/bash i=1while [ $i -le 10000 ]doa=`echo `< /dev/urandom tr -dc A-Za-z0-9 | head -c6``echo ...
- zabbix 监控第三方网络
背景 业务需要到一些第三方网络取数据,有时业务不能用,就需要跑到服务器上telnet第三方端口,排查是否网络问题.所以需要一个检测第三方端口的监控. net.tcp.service[service,& ...
- 18.16 gcc-3.4.5编译错误及解决方法集锦
18.16.1 自写BootLoader错误 ERROR : boot.c:: warning: return type of 'main' is not `int' ANSWER : int mai ...