官术网_书友最值得收藏!

The By.linkText() method

As the name suggests, the By.linkText locating mechanism can only be used to identify the HTML links. Before we start discussing how WebDriver can be commanded to identify a link element using link text, let's see what an HTML link element looks like. The HTML link elements are represented on a web page using the <a> tag, an abbreviation for the anchor tag. A typical anchor tag looks like this:

<a  title="My Account">My Account</a>

Here, href is the link to a different page where your web browser will take you when you click on the link. So, the preceding HTML code when rendered by the browser looks like this:

This MY ACCOUNT is the link text. So the By.linkText locating mechanism uses this text on an anchor tag to identify the WebElement. The code would look like this:

@Test
public void byLinkTextLocatorExample() {
WebElement myAccountLink =
driver.findElement(By.linkText("MY ACCOUNT"));
myAccountLink.click();
assertThat(driver.getTitle())
.isEqualTo("Customer Login");
}

Here, the By.linkText locating mechanism is used to identify the MY ACCOUNT link.

The linkText and partialLinkText methods are case-sensitive. 
主站蜘蛛池模板: 柏乡县| 伊宁县| 慈利县| 阿合奇县| 全椒县| 荣昌县| 扬中市| 白城市| 石台县| 古交市| 峨眉山市| 平潭县| 曲松县| 五指山市| 湄潭县| 平远县| 秦皇岛市| 海伦市| 凯里市| 辉县市| 淮北市| 鹤山市| 睢宁县| 哈巴河县| 房产| 奉贤区| 宜阳县| 瓦房店市| 涪陵区| 东阳市| 喀喇沁旗| 陇川县| 普宁市| 田阳县| 资溪县| 内丘县| 广灵县| 伊春市| 常熟市| 固始县| 蒲江县|