*
Matches any element node.
@*
matches any attribute node.
Node ()
Matches any type of node.
InstanceIn the table below, we list some path expressions and the results of these expressions:
Path Expression
Results
/bookstore/*
Selects all child elements of the bookstore element.
//*
Selects all elements in the document.
Title[@*]
Select all the t
'] means ID is content So: This example means: any sub-tags with the id content below the second div tag, below the UL label XPath basic learning is complete, next step to start learning P[text () = ' A ']: P tag with text a P[text () = ' A ']: text contains P tags for a a[@class = ' abc ']: P tag Class A (of course.) Since it is possible for @class to be able to use @id, why do not associate @src and @href it? ) P[not (@class = ' a ')]: P tag wit
Turn from: http://www.cnblogs.com/qingchunjun/p/4208159.html
By.xpath ()
This method is a very powerful way to find elements, which can be used to locate almost any element on the page. Before we can formally start using XPath for positioning, let's take a look at what XPath is. XPath is the abbreviation for XML path, because the HTML document itself is a standa
When writing selenium cases, XPath is rarely used. Now there are a lot of reference materials about the use of xpath. Next I will directly turn to a document about the use of xpath. If you are not familiar with XPath, refer to the following section. You do not need to go to
Overview
A previous blog post roughly describes the first demo based on Lazyui, which describes the design and use of this tool in detail.
element Get plugin : Lazyui Elements Extractor, as a chrome plugin, used to crawl common controls on a page (either batch or single fetch), to get the XPath of the frame and three uniquely positioned controls on which the control is located , and generates Java code based on the Lazyui framework to solve the probl
XPath can quickly navigate to a node or attribute in the XML. The XPath syntax is simple, but powerful enough, and it is also the basic knowledge of using XSLT.Sample xml:
1234567891011121314151617181920212223242526272829
xmlversion="1.0" encoding="utf-8" ?>pets>cat color="black" weight="10">price>100price>desc>this is a black catdesc>cat>catcolo
In selenium automation, if the ID, class, name, etc General Locator cannot find the element, the XPath is used to find the element on the Web page.This time I will explain from the following three aspects:1. What is XPath2. Use of XPath syntax3. Use XPath to handle complex and dynamic elements in selenium1.
index number to locate
In the tested Web page, look for the query button in the second div tag
INPUT[2]
webelement button = driver.findelement (By.xpath ("//input[2]"));
Use Page properties to locate
Locate the first picture element in the page being tested
img[@alt = ' div1-img1 ']
webelement button = driver.findelement (By.xpath ("//img[@alt = ' div1-img1 ')");
Fuzzy positioning Starts-with Keywords
Find pictures alt attribute start position contains elements
the previous steps, we click on the line of code that knows the element we want to get. At this point, we move the mouse over the line code, right-click and select Copy---copy Xpath. This allows us to get an XPath expression for that element. We can see the XPath expression only by selecting paste in any of the input boxes. For example, our Baidu homepage exampl
element is the same as its tag, this time cannot be positioned through the hierarchy, the index can be positioned as follows:driver.find_element_by_xpath("//select[@id=‘nr‘]/option[1]").click()driver.find_element_by_xpath("//select[@id=‘nr‘]/option[2]").click()driver.find_element_by_xpath("//select[@id=‘nr‘]/option[3]").click()The index here starts at 1, not the same as the Python index.6. XPath Logic operationsXPath is supported with (and), or (or),
The furthest distance in the world is probably to see a page element chu there, but I can't locate it!!
There are many ways to locate elements, such as through IDs, name, Class_name, Tag_name, Link_text, and so on, but the limitations of these methods are selenium, and the id attribute, first of all, must not have an id attribute for each element. The id attribute of the second element is not necessarily invariant. So these methods to understand,
ObjectiveIn general, we can navigate to the target element with simple XPath, but it is difficult to navigate in a simple way for some without ID and no name, and other properties are dynamic.In this case, we need to use xpath1.0 built-in functions for positioning, and here we focus on 3 functions:
Contains
Sibling
Contains functionWith the contains function, we can extract all elements that match a particular text.For example, on th
XPath begins parsing from the root node of the documentThe relative path begins with "//" and allows the XPath to begin parsing from any element node of the documentRelative path Positioning methodIn the tested Web page, find the button in the first div tagAn XPath expressioninput[@value = "Query"]Webelement button = driver.findelement (By.xpath ("//input[@value
Driver.find_element_by_xpath (input[@id = "kw"])The above code, I believe a lot of learning Selenium + python friends are very familiar with, is to locate Baidu home search box code, if we want to "kw", with a variable to indicate how to operate it?At present, I know there are two ways, such as the next, is to locate the Baidu search box, click the Search code, in the process of XPath positioning, using the
# with contains, look for the page where the Style property value contains all the DIV elements with the keyword sp.gif, where the @ can be followed by any property name of the element.Self.driver.find_element_by_xpath ('//div[contains (@style, "Sp.gif")] '). Click ()# with Start-with, look for a DIV element with the style attribute starting with position, where the @ can be followed by any property name of the element.Self.driver.find_element_by_xpath ('//div[start-with (@style, "position")] ')
1.xptah can be positioned by the attributes of the element's ID, name, classDriver.find_element_by_xpath ("//input[@id = ' kw1 ']")Driver.find_element_by_xpath ("//*[@name = ' wd ']")Driver. Find_element_by_xpath ("//*[@class = ' s_ipt ']") 2. If an element ID, name, and class attribute are not available, you can also navigate to theDriver.find_element_by_xpath ("//*[@autocomplete = ' off ']")Driver.find_element_by_xpath("//input[@type = ' text ']")3. Logical operation4.
[Original address: http://www.cnblogs.com/hya1109/archive/2007/12/16/996535.html]
I have also sent a message about. net, but it is not very detailed. Now I will introduce in detail how to operate XML files in C #, just like learning to operate a database and learn the SQL language, before learning to operate XML and the language, we need to familiarize ourselves with the XML "SQL" Statement XPath. Since this series of posts does not aim to introduce t
the parent node of the current node
Preceding
XPath ('./preceding::* ')
Selects all nodes in the document before the start tag of the current node
Preceding-sibling
XPath ('./preceding-sibling::* ')
Select the sibling node before the current node
Self
XPath ('./self::* ')
Sele
the parent node of the current node
Preceding
XPath ('./preceding::* ')
Selects all nodes in the document before the start tag of the current node
Preceding-sibling
XPath ('./preceding-sibling::* ')
Select the sibling node before the current node
Self
XPath ('./self::* ')
Sele
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.