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

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. 
主站蜘蛛池模板: 涪陵区| 霍林郭勒市| 丹凤县| 景宁| 泽普县| 会东县| 江西省| 肥城市| 乌鲁木齐市| 卢氏县| 若羌县| 宁德市| 峨山| 仁怀市| 洪江市| 高唐县| 蒙阴县| 太康县| 盐津县| 文水县| 隆子县| 安陆市| 宜阳县| 平乐县| 偏关县| 泰州市| 始兴县| 金昌市| 建平县| 乌兰察布市| 监利县| 宜黄县| 商都县| 东光县| 年辖:市辖区| 陆良县| 泾源县| 抚宁县| 甘德县| 临汾市| 淮滨县|