#!/usr/bin/env python
# -*- coding:utf-8 -*-
'''
Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)
''' from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys import time,os
import random # about:addons 火狐浏览器安装组件,访问的地址 # <input id="kw" name="wd" class="s_ipt" value="" maxlength="255" autocomplete="off">
#id
keys="测试部落"
delay=3
url="https://www.baidu.com/"
url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/pop08.html"
url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/box08.html"
url="file:///D:/ideaSpace/autoProject/python_autotest/nicetime/webdriver/table08.html"
driver=webdriver.Firefox() #弹出框 主要分 alert confirm prompt
#主要的方法有 获取文本值:text 输入内容:send_keys 取消:dismiss 确定:accept driver.get(url)
time.sleep(delay) #单选按钮操作
driver.find_element_by_id("boy").click() #判断选择的状态
flag=driver.find_element_by_id("girl").is_selected()
print(flag) #复选框操作
boxs=driver.find_elements_by_xpath(".//*[@type='checkbox']")
for i in boxs:
i.click() #弹窗处理 alter confirm prompt
driver.find_element_by_id("alert").click()
driver.find_element_by_id("confirm").click()
driver.find_element_by_id("prompt").click()
time.sleep(delay) t=driver.switch_to_alert()
print(t.text) t.send_keys("需要输入你想要查看的")
#
t.accept
#
# t.dismiss() # 表格页面数据获取
# 里面的body要换成tbody 行和列中的值可按顺序获取值
t=driver.find_element_by_xpath(".//*[@id='mytable']/tbody/tr[2]/td[1]")
print(t.text) driver.quit()

Python3+Selenium3+webdriver学习笔记8(单选、复选框、弹窗处理)的更多相关文章

  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. 《jquery权威指南2》学习笔记------ jquery获取复选框的值

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...

  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. [xdoj1227]Godv的数列(crt+lucas)

    解题关键:1001=7*11*13,模数非常小,直接暴力lucas.递归次数几乎为很小的常数.最后用中国剩余定理组合一下即可. 模数很小时,一定记住lucas定理的作用 http://acm.xidi ...

  2. 第一个PyQuery小demo

    1.打开网址https://www.v2ex.com/,查看其源码. 2.打开PyCharm编译器,新建工程c3-11,新建python file,命名为v2ex.py,同时,新建file,命名为v2 ...

  3. 51nod1069【Nim取石子游戏】

    具体看:萌新笔记之Nim取石子游戏可以这么写: #include <bits/stdc++.h> using namespace std; typedef long long LL; in ...

  4. 洛谷P2867 [USACO06NOV]大广场Big Square

    P2867 [USACO06NOV]大广场Big Square 题目描述 Farmer John's cows have entered into a competition with Farmer ...

  5. 大整数因子(高精mod)

    大整数的因子 总时间限制:  1000ms 内存限制:  65536kB 描述 已知正整数k满足2<=k<=9,现给出长度最大为30位的十进制非负整数c,求所有能整除c的k. 输入 一个非 ...

  6. 洛谷P2289 [HNOI2004]邮递员(插头dp)

    传送门 太神仙了……讲不来讲不来->这里 //minamoto #include<iostream> #include<cstdio> #include<cstri ...

  7. java中对List进行分组和排序

    排序 对List进行排序,有两种办法 第一个是用java提供的工具类Collections提供的sort方法进行排序 废话不多说,上代码 首先定义一个Student public class Stud ...

  8. 关于表格——增加删除行,鼠标选定(利用JavaScript)

    涉及到的知识点: 1.onmouseover,onmouseout 2.dom getElementByTagName 3.新建节点元素createElement; <!DOCTYPE html ...

  9. [題解](水/數學)luogu_P1147連續自然數和

    尺取法a掉 然而數學解法為 等差數列求和公式: sum(L,R)=(L+R)(R-L+1)/2=M 即(L+R)(R-L+1)=2M 可以把2M分解成两个数之积,假设分成了两个数K1,K2,且K1&l ...

  10. CC08:翻转子串

    题目 假定我们都知道非常高效的算法来检查一个单词是否为其他字符串的子串.请将这个算法编写成一个函数,给定两个字符串s1和s2,请编写代码检查s2是否为s1旋转而成,要求只能调用一次检查子串的函数. 给 ...