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

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. 
主站蜘蛛池模板: 西宁市| 永和县| 海城市| 泾川县| 客服| 涟水县| 遂平县| 宾川县| 二手房| 申扎县| 平江县| 南岸区| 沅江市| 克什克腾旗| 泰安市| 凤阳县| 奈曼旗| 龙南县| 林西县| 慈利县| 灵台县| 盐边县| 扬中市| 正定县| 思南县| 余江县| 永和县| 宁津县| 高平市| 安化县| 广南县| 尚志市| 大田县| 安乡县| 恩施市| 蒙自县| 外汇| 文登市| 虞城县| 麻江县| 西平县|