Selenium webdriver-UI Element定位
转:http://blog.csdn.net/jillliang/article/details/8206402
1.创建Fixfox web driver实例
WebDriver driver = new ForefoxDriver();
WebDriver driver = new InternetExplorerDriver();
2.获取Web page
driver.get("http://www.google.com");
或者
driver.navigate().to("http://www.google.com");
//navigate().to和get()其实作用是一样的,但是navigate还可以进行浏览器的前进后退操作:
driver.navigate().forward();
driver.navigate.back();
3. 定位UI Element
先安装FireBug(http://getfirebug.com/), 然后用FireBug定位页面元素的值。 如下图所示,只要把firebug的箭头放到要定位的元素上,就可以得到该元素对应标签的值, 比如goole的textbox:<input id="lst-ib" class="lst lst-tbb" type="text" maxlength="2048" name="q" autocomplete="off" size="41" title="Google 搜索" value="">, 然后我们就可以通过name, id, class等属性来定位这个输入框。
3.1. 通过id
WebElement element = driver.findElement(By.id("lst-ib"));
3.2. 通过class name
WebElement element = driver.findElement(By.className("lst lst-tbb"));
3.3. 通过Name
WebElement element = driver.findElement(By.name("q"));
3.4. 通过 Tag Name
WebElement frame =driver.findElement(By.tagName("iframe"));
3.5. 通过 Link Text
WebElement cheese=driver.findElement(By.linkText("cheese"));
3.6. 通过 Partial Link Text
WebElement cheese=driver.findElement(By.partialLinkText("cheese"));
3.7. 通过CSS
WebElementcheese=driver.findElement(By.cssSelector("#food span.dairy.aged"));
3.8. 通过XPATH [注意:XPATH在IE上速度会比较慢,所以推荐使用css selector]
List<WebElement>inputs=driver.findElements(By.xpath("//input"));
3.9. 通过JavaScript
WebElement element=(WebElement)((JavascriptExecutor)driver).executeScript("return
$('.cheese')[0]");
Selenium webdriver-UI Element定位的更多相关文章
- selenium webdriver 表格的定位方法练习
selenium webdriver 表格的定位方法 html 数据准备 <html> <body> <div id="div1"> <i ...
- Selenium WebDriver 8大定位方式
Selenium WebDriver 8大定位方式: driver.find_element_by_id() driver.find_element_by_name() driver.find_ele ...
- Java + Selenium + WebDriver八大元素定位方式
UI自动化测试的第一步就是进行元素定位,下面给大家介绍一下Selenium + WebDriver的八大元素定位方式.现在我们就以百度搜索框为例进行元素定位,如下图: 一.By.name() Java ...
- Selenium WebDriver UI对象库
UI对象库:使用配置文件存储测试页面上的定位和定位表达式,做到定位数据和程序的分离. 第一步:实现工具类Object工具类,供测试程序调用. /** * 使用配置文件存储测试页面上的定位和定位表达式, ...
- [selenium webdriver Java]元素定位——findElement/findElements
策略 语法 语法 描述 By id driver.findElement(By.id()) driver.findElements(By.id()) 通过id属性定位元素 By name driver ...
- selenium webdriver python 元素定位
总结 定位查找时,返回查找到的第一个match的元素.如果找不到,则 raise NoSuchElementException 单个元素定位: find_element_by_idfind_e ...
- selenium WebDriver 八种定位方式源码
/* * 多种元素定位方式 */ package com.sfwork; import java.util.List; import org.openqa.selenium.By; import or ...
- selenium webdriver XPath的定位方法练习 !
html 代码: <html> <body> <div id="div1"> <input name="divl1input& ...
- PhantomJS + Selenium webdriver 总结-元素定位
webdriver提供了丰富的API,有多种定位策略:id,name,css选择器,xpath等,其中css选择器定位元素效率相比xpath要高些,使用id,name属性定位元素是最可靠,效率最高的一 ...
- Selenium Webdriver——Xpath轴定位(preceding)
1.preceding-sibling 选取当前节点之前的所有同级节点 text=出发之前的同级节点: 2.preceding 选取当前节点开始标签之前的所有节点 text=出发节点标签之前的所有i ...
随机推荐
- PHP无限级分类实现(递归+非递归)
<?php /** * Created by PhpStorm. * User: qishou * Date: 15-8-2 * Time: 上午12:00 */ //准备数组,代替从数据库中检 ...
- Spring Boot (14) 数据源配置原理
数据源配置源码 这里截取org.springframework.boot.autoconfigure.jdbc.DataSourceConfiguration的部分源码,主要介绍Tomcat和Hika ...
- @PathVariable注解的使用和@Requestparam
一. @PathVariable @PathVariable这是一个路径映射格式的书写方式注解,在类映射路径的后加上/{对应方法参数中属性@PathVariable("code") ...
- 用 Django2.0 做 简单的BBS(前端用 Bootstrap)
实现目标: 开发首页显示BBS的标题和摘要,点击BBS的标题可跳转到BBS详细页面进行展示. 开发环境及开发工具: Python 3.6.3 Django 2.0 Pycharm 2017.3 实现过 ...
- 深入浅出java多态
所谓多态就是指程序中定义的引用变量所指向的具体类型和通过该引用变量发出的方法调用在编程时并不确定,而是在程序运行期间才确定,即一个引用变量倒底会指向哪个类的实例对象,该引用变量发出的方法调用到底是哪个 ...
- 【Hexo】deploy出错的解决方法
.ERROR Deployer not found: git 执行npm install hexo-deployer-git --save .$ hexo d INFO Deploying: git ...
- matlab学习使用Button Group绘制不同的正弦曲线
创建buttongroup控件---即按钮组 再添加三个radiobutton 对其设置 buttongroup控件改Title为绘制不同正弦曲线 第一个radiobutton的string改为sin ...
- PAT_A1015#Reversible Primes
Source: PAT A1015 Reversible Primes (20 分) Description: A reversible prime in any number system is a ...
- python之testlink模块
1.安装:pip install TestLink-API-Python-client >>>>>>待续
- C语言右移操作在汇编层面的相关解释
在 CSDN 看到帖子回复如下: x=y>>2;004122A8 mov eax,dword ptr [y] 004122AB sar eax,2 '算 ...