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

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. 
主站蜘蛛池模板: 绥芬河市| 望江县| 宜黄县| 沂水县| 桐乡市| 灵武市| 大余县| 尼勒克县| 灵山县| 东台市| 皮山县| 翼城县| 江津市| 黔南| 芦溪县| 郁南县| 轮台县| 南澳县| 班玛县| 突泉县| 沂水县| 安溪县| 临邑县| 纳雍县| 霍城县| 汉源县| 久治县| 龙门县| 博兴县| 扎兰屯市| 霍林郭勒市| 土默特左旗| 佛冈县| 鄂伦春自治旗| 游戏| 云安县| 泊头市| 津市市| 青田县| 通州区| 高要市|