webDriver API——第12部分WebElement
class selenium.webdriver.remote.webelement.WebElement(parent, id_)
Bases: object
Represents a DOM element.
Generally, all interesting operations that interact with a document will be performed through this interface.
All method calls will do a freshness check to ensure that the element reference is still valid. This essentially determines whether or not the element is still attached to the DOM. If this test fails, then an StaleElementReferenceException is thrown, and all future calls to this instance will fail.
- clear()
-
Clears the text if it’s a text entry element.
- click()
-
Clicks the element.
- find_element(by='id', value=None)
- find_element_by_class_name(name)
-
Finds element within this element’s children by class name.
Args: - name - class name to search for.
- find_element_by_css_selector(css_selector)
-
Finds element within this element’s children by CSS selector.
Args: - css_selector - CSS selctor string, ex: ‘a.nav#home’
- find_element_by_id(id_)
-
Finds element within this element’s children by ID.
Args: - id_ - ID of child element to locate.
- find_element_by_link_text(link_text)
-
Finds element within this element’s children by visible link text.
Args: - link_text - Link text string to search for.
- find_element_by_name(name)
-
Finds element within this element’s children by name.
Args: - name - name property of the element to find.
- find_element_by_partial_link_text(link_text)
-
Finds element within this element’s children by partially visible link text.
Args: - link_text - Link text string to search for.
- find_element_by_tag_name(name)
-
Finds element within this element’s children by tag name.
Args: - name - name of html tag (eg: h1, a, span)
- find_element_by_xpath(xpath)
-
Finds element by xpath.
Args: xpath - xpath of element to locate. “//input[@class=’myelement’]” Note: The base path will be relative to this element’s location.
This will select the first link under this element.
myelement.find_elements_by_xpath(".//a")However, this will select the first link on the page.
myelement.find_elements_by_xpath("//a")
- find_elements(by='id', value=None)
- find_elements_by_class_name(name)
-
Finds a list of elements within this element’s children by class name.
Args: - name - class name to search for.
- find_elements_by_css_selector(css_selector)
-
Finds a list of elements within this element’s children by CSS selector.
Args: - css_selector - CSS selctor string, ex: ‘a.nav#home’
- find_elements_by_id(id_)
-
Finds a list of elements within this element’s children by ID.
Args: - id_ - Id of child element to find.
- find_elements_by_link_text(link_text)
-
Finds a list of elements within this element’s children by visible link text.
Args: - link_text - Link text string to search for.
- find_elements_by_name(name)
-
Finds a list of elements within this element’s children by name.
Args: - name - name property to search for.
- find_elements_by_partial_link_text(link_text)
-
Finds a list of elements within this element’s children by link text.
Args: - link_text - Link text string to search for.
- find_elements_by_tag_name(name)
-
Finds a list of elements within this element’s children by tag name.
Args: - name - name of html tag (eg: h1, a, span)
- find_elements_by_xpath(xpath)
-
Finds elements within the element by xpath.
Args: - xpath - xpath locator string.
Note: The base path will be relative to this element’s location.
This will select all links under this element.
myelement.find_elements_by_xpath(".//a")However, this will select all links in the page itself.
myelement.find_elements_by_xpath("//a")
- get_attribute(name)
-
Gets the given attribute or property of the element.
This method will first try to return the value of a property with the given name. If a property with that name doesn’t exist, it returns the value of the attribute with the same name. If there’s no attribute with that name, None is returned.
Values which are considered truthy, that is equals “true” or “false”, are returned as booleans. All other non-None values are returned as strings. For attributes or properties which do not exist, None is returned.
Args: - name - Name of the attribute/property to retrieve.
Example:
# Check if the "active" CSS class is applied to an element.
is_active = "active" in target_element.get_attribute("class")
- is_displayed()
-
Whether the element is visible to a user.
- is_enabled()
-
Returns whether the element is enabled.
- is_selected()
-
Returns whether the element is selected.
Can be used to check if a checkbox or radio button is selected.
- send_keys(*value)
-
Simulates typing into the element.
Args: - value - A string for typing, or setting form fields. For setting
file inputs, this could be a local file path.
Use this to send simple key events or to fill out form fields:
form_textfield = driver.find_element_by_name('username')
form_textfield.send_keys("admin")This can also be used to set file inputs.
file_input = driver.find_element_by_name('profilePic')
file_input.send_keys("path/to/profilepic.gif")
# Generally it's better to wrap the file path in one of the methods
# in os.path to return the actual path to support cross OS testing.
# file_input.send_keys(os.path.abspath("path/to/profilepic.gif"))
- submit()
-
Submits a form.
- value_of_css_property(property_name)
-
The value of a CSS property.
- id
-
Internal ID used by selenium.
This is mainly for internal use. Simple use cases such as checking if 2 webelements refer to the same element, can be done using ==:
if element1 == element2:
print("These 2 are equal")
- location
-
The location of the element in the renderable canvas.
- location_once_scrolled_into_view
-
THIS PROPERTY MAY CHANGE WITHOUT WARNING. Use this to discover where on the screen an element is so that we can click it. This method should cause the element to be scrolled into view.
Returns the top lefthand corner location on the screen, or None if the element is not visible.
- parent
-
Internal reference to the WebDriver instance this element was found from.
- rect
-
A dictionary with the size and location of the element.
- size
-
The size of the element.
- tag_name
-
This element’s tagName property.
- text
-
The text of the element.
webDriver API——第12部分WebElement的更多相关文章
- Webdriver API (二)
(转载) 1.3 打开测试页面 对页面对测试,首先要打开被测试页面的地址(如:http://www.google.com),web driver 提供的get方法可以打开一个页面: // And no ...
- webdriver API中文文档
1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGuide:http://seleniu ...
- python+selenium自动化软件测试(第2章):WebDriver API
2.1 操作元素基本方法 前言前面已经把环境搭建好了,从这篇开始,正式学习selenium的webdriver框架.我们平常说的 selenium自动化,其实它并不是类似于QTP之类的有GUI界面的可 ...
- 2.28 查看webdriver API
2.28 查看webdriver API(带翻译) 前言 前面都是点点滴滴的介绍selenium的一些api使用方法,那么selenium的api到底有多少呢?本篇就教大家如何去查看seleni ...
- Webdriver API中文版
Webdriver API中文版 1.1 下载selenium2.0的lib包 http://code.google.com/p/selenium/downloads/list 官方UserGui ...
- 转:python webdriver API 之操作测试对象
一般来说,所有有趣的操作与页面交互都将通过 WebElement 接口,包括上一节中介绍的对象定位,以及本节中需要介绍的常对象操作.webdriver 中比较常用的操作元素的方法有下面几个: cle ...
- 5.6 WebDriver API实例讲解(31-35)
31.判断页面元素是否存在 public static void testElementExist(){ driver.get("http://www.sogou.com"); t ...
- selenium2(WebDriver) API
selenium2(WebDriver) API 作者:Glen.He出处:http://www.cnblogs.com/puresoul/ 1.1 下载selenium2.0的包 官方downl ...
- Selenium2+Python:Webdriver API速记手册
由于web自动化常常需要控制浏览器行为和操作页面元素,相关函数又比较多,于是再此记下一份Webdriver API查阅文档以备不时之需. 参考:虫师<Selenium2自动化测试实战>,和 ...
随机推荐
- python3实践-从网站获取数据(Carbon Market Data-BJ) (pandas,bs4)
自己边看边实践一些简单的实际应用,下面的程序是从某个网站上获取需要的数据. 在编写的过程中,通过学习陆续了解到一些方法,发现Python真的是很便捷. 尤其是用pandas获取网页中的表格数据,真的是 ...
- Python开发基础-Day16import模块导入和包的调用
模块概念 在Python中,一个.py文件就称之为一个模块(Module).使用模块组织代码,最大的好处是大大提高了代码的可维护性 模块一共三种:python标准库.第三方模块.应用程序自定义模块. ...
- JDBC 编程
DAO设计 没有使用DAO存在的问题:多个地方都要都同时做CRUD操作时,重复的代码就会很多. DAO:Data Access Object(数据存取对象). 位于业务逻辑和持久化数据之间,实现对持久 ...
- luogu P1047 校门外的树
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是1米.我们可以把马路看成一个数轴,马路的一端在数轴0的位置,另一端在L的位置:数轴上的每个整数点,即0,1,2,……,L,都种 ...
- 【jzyzoj】【p1320 patrol】 巡逻(网络流最小割例题)
描述 Description FJ有个农场,其中有n块土地,由m条边连起来.FJ的养牛场在土地1,在土地n有个新开张的雪糕店.Bessie经常偷偷溜到雪糕店,当Bessie去的时候,FJ就要跟上她.但 ...
- [Lydsy1805月赛] quailty 算法
稍微建一下模型就可以发现,题目要求的其实是一个最小异或基环森林.... 可以用类似最小生成树的拟阵性质来证明,贪心的从小的边权开始依次尝试加入的方法是对的. 所以我们把a[]排完序之后直接递归贪心就行 ...
- 【递推】【DFS】【枚举】Gym - 101246C - Explode 'Em All
网格里放了一些石块,一个炸弹能炸开其所在的行和列.问炸光石块至少要几个炸弹. 枚举不炸开的行数,则可以得出还要炸开几列. 为了不让复杂度爆炸,需要两个优化. 先是递推预处理出f(i)表示i的二进制位中 ...
- “过时”的SpringMVC我们到底在用什么?深入分析DispatchServlet源码
之前已经分析过了Spring的IOC(<零基础带你看Spring源码--IOC控制反转>)与AOP(<从源码入手,一文带你读懂Spring AOP面向切面编程>)的源码,本次就 ...
- Promise对象的基本用法
主要作用 1.用来传递异步操作的消息 2.三种状态:pending.Resolved.Rejected,而且只能从第一种状态转到后两者状态之一. 3.缺点 (1)一旦新建就会立即执行 (2)如果不设置 ...
- 最小生成树(Prime算法)
最小生成树一·Prim算法 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 最近,小Hi很喜欢玩的一款游戏模拟城市开放出了新Mod,在这个Mod中,玩家可以拥有不止一个城 ...