webdriver之select、alert、prompt、confirm
select_by_index() :通过索引定位
select_by_value() :通过value值定位
select_by_visible_text() :通过文本值定位
deselect_all() :取消所有选项
deselect_by_index() :取消对应index选项
deselect_by_value() :取消对应value选项
deselect_by_visible_text() :取消对应文本选项
first_selected_option() :返回第一个选项
all_selected_options() :返回所有的选项
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
driver = webdriver.Firefox()
driver.get('https://www.baidu.com')
driver.implicitly_wait(2)
mouse = driver.find_element_by_link_text('设置')
ActionChains(driver).move_to_element(mouse).perform()
driver.find_element_by_link_text('搜索设置').click()
# 分两步定位
# s = driver.find_element_by_id('nr')
# s.find_element_by_xpath('//option[@value="50"]').click()
# 一步定位,select下选项的索引从1开始
# driver.find_element_by_xpath('.//select[@id ="nr"]/option[3]').click()
# 高级玩法
s = driver.find_element_by_id('nr')
# Select(s).select_by_index(2) #索引位置从0开始
# Select(s).select_by_value('50')
Select(s).select_by_visible_text('每页显示50条')
driver.find_element_by_link_text('保存设置').click()
# 获取alert弹框
t = driver.switch_to.alert
print(t.text)
t.accept()
二、alert操作
1.先用switch_to_alert()方法切换到alert弹出框上
2.可以用text方法获取弹出的文本 信息
3.accept()点击确认按钮
4.dismiss()相当于点右上角x,取消弹出框
三、confirm操作
1.先用switch_to_alert()方法切换到alert弹出框上
2.可以用text方法获取弹出的文本 信息
3.accept()点击确认按钮
4.dismiss()相当于点取消按钮或点右上角x,取消弹出框
四、prompt操作
1.先用switch_to_alert()方法切换到alert弹出框上
2.可以用text方法获取弹出的文本 信息
3.accept()点击确认按钮
4.dismiss()相当于点右上角x,取消弹出框
5.send_keys()这里多个输入框,可以用send_keys()方法输入文本内容
from selenium import webdriver
url = 'file:///E:/my_learn/test.html'
driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_id('prompt').click()
t = driver.switch_to.alert
print(t.text)
t.send_keys('hello prompt')
# t.accept()
t.dismiss()
webdriver之select、alert、prompt、confirm的更多相关文章
- 转:python webdriver API 之alert/confirm/prompt 处理
webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...
- selenium webdriver学习(七)------------如何处理alert、confirm、prompt对话框( 转)
selenium webdriver学习(七)------------如何处理alert.confirm.prompt对话框 博客分类: Selenium-webdriver alertpromptc ...
- jquery自定义对话框alert、confirm和prompt
jQuery Alert Dialogs,又一个基于jQuery的提示框插件,主要包括Alert.Confirm.prompt这三种,还有一个高级范例,可以在提示框内嵌入HTML语言,可以自定义风格样 ...
- Selenium2学习-040-JavaScript弹出框(alert、confirm、prompt)操作演示实例
弹出框是网页自动化测试常见得操作页面元素之一,常见的JavaScript弹出框有如下三种: 1.alert(message):方法用于显示带有一条指定消息和一个 OK 按钮的警告框.DemoAlert ...
- 如何处理alert、confirm、prompt对话框
import java.io.File; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.ope ...
- 基于Selenium2+Java的UI自动化(6)-操作Alert、confirm、prompt弹出框
alert.confirm.prompt这样的js对话框在selenium1 时代处理起来比价麻烦,常常要用autoit来帮助处理.而现在webdriver对这些弹出框做了专门的处理,使用seleni ...
- Selenium对于对话框alert,confirm,prompt的处理
html 源码: <html> <head> <title>Alert</titl ...
- Selenium常用操作汇总二——如何处理alert、confirm、prompt对话框
alert.confirm.prompt这样的js对话框在selenium1.X时代也是难啃的骨头,常常要用autoit来帮助处理. 试用了一下selenium webdriver中处理这些对话框十分 ...
- selenium+Python(alert 、confirm 、prompt 的处理)
alert\confirm\prompt 弹出框操作主要方法有: text 返回 alert/confirm/prompt 中的文字信息 accept 点击确认按钮 dismiss 点击取消按钮, ...
随机推荐
- 兼容在安装linux系统过程中不支持非原装的光模块的命令
1 .通过ifconfig -a发现有网卡找不到,并且配置没有问题,那么很可能是光模块有问题2 .dmesg | grep 82599EB ,通过这个命令过滤发现有如下信息: [ 7142.12197 ...
- Logstash安装介绍
前言 logstash是ELK日志系统中的一部分,主要承担将收集完成日志进行过滤,并且输出到es的职责. logstash本身也可以作为客户端部署到应用系统的服务器上进行日志收集,但是由于资源开销占用 ...
- 读书笔记一【哈希——MD5】
计算机中,将某种数据转换成指定范围内的数字数字或字母叫做哈希(散列.hashing) 哈希后的值无法像加密解密那样恢复为原文值,通常用于文件校验或数字签名等 好的散列算法应具有: 充分利用所有数据位 ...
- iPhone手机屏幕尺寸(分辨率)
第一代iPhone2G屏幕为3.5英吋,分辨率为320*480像素,比例为3:2. 第二代iPhone3G屏幕为3.5英吋,分辨率为320*480像素,比例为3:2. 第三代iPhone3GS屏幕为3 ...
- 自定义bash提示符
http://adamcavendish.is-programmer.com/posts/35659.html
- hybrid简单了解
技术点总有它的来由. 文章概要: 1.hybrid 基本概念 2.前端和客户端的交互 3.前端和客户端的交互实现 4.前端交互实现关注点 5.小结 1.hybrid 基本概念 ⑴.什么是hybrid? ...
- postman headers 请求参数和MD5加密签名
postman 变量可以这样写:{{timestamp}} ,也可以用系统的,{{$timestamp}},这样就不用给自己赋值了,但在 pre-requestScript中是获取不到这个值的 所以我 ...
- Oracle 10g RAC OCR、Voting disk更换
环境:OEL 5.7 + Oracle 10.2.0.5 RAC 需求:更换存储,OCR.Voting disk同时需要更换到新存储. 1.替换OCR 2.替换voting disk 1.替换OCR ...
- linux 命令 创建 Django 项目 使用路由返回首页界面
1.安装mysql数据库 2.安装pymysql.pip3 install pymysql 3.首先使用cd 命令进入创建的项目文件夹 4.使用django-admin startproject we ...
- 从Redis到Codis移植实践
一. 背景 随着业务的发展,线上Redis的数据越来越多,所以必须考虑扩容的事情了.对于redis的扩容,目前可选的方案有三种:1.client自己做sharding,一般是按key的hash值 ...