控件定位学习:radio、checkbox、ComboBox
来源:互联网 发布:软件设计师考试经验 编辑:程序博客网 时间:2024/06/06 00:27
根据 http://blog.csdn.net/liujingqiu/article/details/50489455 博主的脚步学习了一下网页中一些控件的使用
哈哈哈,昨晚竟然有人问我这个小菜鸟的问题,然后他用的是unittest框架,昨晚百度了一点皮毛,准备用用虽然可以执行,但是好像他的意义与用法不是我想的那样子,还是好好先来简单的吧
在定位select选择框时出错,百度了一下需要引入select模块
其中 http://www.cnblogs.com/yoyoketang/p/6128636.html,这篇文章对select框的定位讲解了六种方法
下面是定位控件的脚本(恰好遇到frame,顺便定位试了试)
from selenium import webdriverfrom selenium.webdriver.support.select import Selectclass ControlsClass(object): def test_open(self): self.driver = webdriver.Chrome() self.driver.maximize_window() self.driver.get("https://register.rediff.com/register/register.php") def test_radio(self): #raido定位并选择女 try: Radio = self.driver.find_element_by_xpath('//*[@id="tblcrtac"]/tbody/tr[24]/td[3]/input[1]') #//*[@id="tblcrtac"]/tbody/tr[24]/td[3]/input[1] if Radio.is_selected() == False: Radio.click() print('radio is seleted') else: print('radio is seleted') except Exception as e: print("Exception is", format(e)) #finally: # print("OK") def test_checkBox(self): #选择checkBox控件 try: checkBox = self.driver.find_element_by_xpath('//input[@class="nomargin"]') if checkBox.is_selected() == False: checkBox.click() print('checkBox is selected') else: print('checkBox is selected') except Exception as e: print("Exception is",format(e)) #finally: # print("OK") def test_ComboBox(self): #选择Country下拉框的Chian选项 try: ComboBox = Select(self.driver.find_element_by_id("country")) #需要导入select 模块 #选择Chian ComboBox.select_by_visible_text("China") return print("ComBox selected") except Exception as e: print("Exception is",format(e)) #finally: # print("OK") def test_Frame(self): #尝试定义Frame try: self.driver.switch_to.frame("metric_iframe") print("frame is selected") except Exception as e : print("Exception is ",format(e))if __name__ =='__main__': test = ControlsClass() test.test_open() test.test_radio() test.test_checkBox() test.test_ComboBox() test.test_Frame() test.driver.quit()
我觉得稍微复杂一点的就是select选择框的定位,然后radio、checkbox 记住is_select()方法,其中跟着博主用的try-except-finally还要在多用些, 继续学习记录吧
阅读全文
0 0
- 控件定位学习:radio、checkbox、ComboBox
- Selenium+Python Radio,Checkbox,Link,ComboBox控件
- Radio/combobox控件的用法
- radio控件和checkbox实例
- Android常见控件Radio Checkbox
- 选择类控件-----ComboBox控件---CheckBox控件
- JS操作select checkbox 及radio控件
- js操作input控件【radio、checkbox】
- jquery操作select、checkbox、radio控件
- flex ComboBox控件 学习
- VC中Radio控件的用法,ComboBox控件用法详解
- VC中Radio控件的用法,ComboBox控件用法详解
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- Jquery 操作Html 控件 CheckBox、Radio、Select 控件
- C# 控件学习二:ComboBox
- .net学习记录-comboBox控件
- best-time-to-buy-and-sell-stock-iii
- mybatis之mybatis-generator
- CodeForces 620E New Year Tree 线段树
- 破解IntelliJ Idea
- 【博览网】C++标准库——第三周课程笔记
- 控件定位学习:radio、checkbox、ComboBox
- shiro实现session共享
- plus-one
- python---布尔类型赋值,字符串,len(),转义、拼接、替换、文件操作
- 第2章 开始VBA编程的第一步。
- 文章标题
- 端口大全
- SpringMVC token 防止表单重复提交
- A*B Problem II