xpath xpath and non-positioning

xpath xpath and non-positioning

xpath, page elements described position information path

 

Non-xpath positioning:

1.By.id, to obtain elements based on the element of id

2.By.name, acquires attribute name element according to the element, may be a collection

3.By.tagName, to obtain elements based on the element tag name, can be a collection

4.By.className, to obtain elements according to the style element can be a collection

5.By.cssSelector, to obtain elements according css selector element may be a collection

 For example: By.cssSelector ( "input") is equivalent to By.tagName ( "input"), tab

By.cssSelector(".classNameValue")等同于By.className("classNameValue"),.className

By.cssSelector("#idValue")或者By.cssSelector("input#idValue")等同于By.id("idValue"),#id

By.cssSelector ( "input [id = 'idValue']"), [= attribute 'attribute'] 

6.By.linkText, to obtain elements based on hyperlinked text value of the element

7.By.partialLinkText, to obtain elements based on the value of the text of the hyperlink elements

 

xpath positioning:

1..By.xpath ( "// * [@ attribute =" attribute value "]"), can be followed by a relative path, you can obtain unique indexed positioning element

For example: // * [@ id = 'idValue'],

//*[@class='classValue'] ,

2./html/body/main/div[1]/header/div[1]/div[1]/div[2]/a/img, absolute path

 

When doing web testing experience

1. General xpath with relative paths can be acquired only element positioned.

//*[@class='header-mobile csa']/div/div[2]/div[3]/a/img

2. carry out operations such as clicking on page elements, ensure full page elements to load, you can add elements of delay waiting to acquire, to ensure that the click event can be executed properly.

 wait.until(new ExpectedCondition<WebElement>() 

When an operation is page switching element 3. clicking, elements may be slid into the first page visible sight, carrying out a click operation.

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView();", element);

Guess you like

Origin www.cnblogs.com/AIME/p/11204680.html