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的更多相关文章

  1. 转:python webdriver API 之alert/confirm/prompt 处理

    webdriver 中处理 JavaScript 所生成的 alert.confirm 以及 prompt 是很简单的.具体思路是使用switch_to.alert()方法定位到 alert/conf ...

  2. selenium webdriver学习(七)------------如何处理alert、confirm、prompt对话框( 转)

    selenium webdriver学习(七)------------如何处理alert.confirm.prompt对话框 博客分类: Selenium-webdriver alertpromptc ...

  3. jquery自定义对话框alert、confirm和prompt

    jQuery Alert Dialogs,又一个基于jQuery的提示框插件,主要包括Alert.Confirm.prompt这三种,还有一个高级范例,可以在提示框内嵌入HTML语言,可以自定义风格样 ...

  4. Selenium2学习-040-JavaScript弹出框(alert、confirm、prompt)操作演示实例

    弹出框是网页自动化测试常见得操作页面元素之一,常见的JavaScript弹出框有如下三种: 1.alert(message):方法用于显示带有一条指定消息和一个 OK 按钮的警告框.DemoAlert ...

  5. 如何处理alert、confirm、prompt对话框

    import java.io.File; import org.openqa.selenium.Alert; import org.openqa.selenium.By; import org.ope ...

  6. 基于Selenium2+Java的UI自动化(6)-操作Alert、confirm、prompt弹出框

    alert.confirm.prompt这样的js对话框在selenium1 时代处理起来比价麻烦,常常要用autoit来帮助处理.而现在webdriver对这些弹出框做了专门的处理,使用seleni ...

  7. Selenium对于对话框alert,confirm,prompt的处理

    html 源码: <html>                  <head>                      <title>Alert</titl ...

  8. Selenium常用操作汇总二——如何处理alert、confirm、prompt对话框

    alert.confirm.prompt这样的js对话框在selenium1.X时代也是难啃的骨头,常常要用autoit来帮助处理. 试用了一下selenium webdriver中处理这些对话框十分 ...

  9. selenium+Python(alert 、confirm 、prompt 的处理)

    alert\confirm\prompt 弹出框操作主要方法有: text  返回 alert/confirm/prompt 中的文字信息 accept  点击确认按钮 dismiss 点击取消按钮, ...

随机推荐

  1. LeetCode 538 Convert BST to Greater Tree 解题报告

    题目要求 Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the origi ...

  2. list的基本操作实现

    有关list的相关实现,主函数没有写很多,每个部分目前没发现有问题: #include <iostream> #include <stdio.h> using namespac ...

  3. photoshop 修改pdf文件并保存为pdf

    1.CTRL + O   打开要编辑的pdf文件 按住shift 选中每一页,点击确定. pdf文档每一页以一个psd文件显示在工作区, 分别进行修改, 2.批量修改同一个元素(比如加个图标) 在一页 ...

  4. python练习题-day25

    class Person: __key=123 def __init__(self,username,password): self.username=username self.__password ...

  5. 学习记录----简单的原生js路由

    在以前的web程序中,路由字眼只出现在后台中.但是随着SPA单页面程序的发展,便出现了前端路由一说.单页面顾名思义就是一个网站只有一个html页面,但是点击不同的导航显示不同的内容,对应的url也会发 ...

  6. 【window】mongodb安装和配置

    最近要独立开发vue+mongodb+node的小项目,项目不大,但之前没了解过mongodb还是蛮不容易的,因为以前用MySQL的时候都是用的集成化的工具,完全不用写命令去启动,用mogodb首先需 ...

  7. vi命令删除

    3.删除 x :删除当前光标位置的字符 X    :删除当前光标位置前的字符 dd :删除当前行

  8. 【LeetCode每天一题】Add Binary(二进制加法)

    Given two binary strings, return their sum (also a binary string).The input strings are both non-emp ...

  9. attr 和 prop的使用区别

    自带的属性,用prop:自定义的属性,用attr.

  10. ReLU激活函数的缺点

    训练的时候很”脆弱”,很容易就”die”了,训练过程该函数不适应较大梯度输入,因为在参数更新以后,ReLU的神经元不会再有激活的功能,导致梯度永远都是零. 例如,一个非常大的梯度流过一个 ReLU 神 ...