- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 179字
- 2021-08-13 16:08:08
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.
- 通信網絡基礎與設備
- Building Django 2.0 Web Applications
- Hands-On Chatbot Development with Alexa Skills and Amazon Lex
- Learning QGIS 2.0
- Hands-On Full Stack Development with Spring Boot 2 and React(Second Edition)
- 互聯網基礎資源技術與應用發展態勢(2021—2023)
- NB-IoT物聯網技術解析與案例詳解
- 智慧光網絡:關鍵技術、應用實踐和未來演進
- 6G:面向2030年的移動通信
- 物聯網工程導論(第3版)
- Microsoft Power Platform Enterprise Architecture
- Selenium WebDriver 3 Practical Guide
- 華為HCIA-Datacom認證指南
- Building RESTful Web Services with .NET Core
- 信息技術安全評估準則:源流、方法與實踐