- 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.
- C++黑客編程揭秘與防范
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- Wireshark網(wǎng)絡(luò)分析就這么簡(jiǎn)單
- 中小型局域網(wǎng)組建、管理與維護(hù)實(shí)戰(zhàn)
- Microservice Patterns and Best Practices
- OMNeT++與網(wǎng)絡(luò)仿真
- 2小時(shí)讀懂物聯(lián)網(wǎng)
- Getting Started with Memcached
- Microsoft Power Platform Enterprise Architecture
- 云計(jì)算技術(shù)與標(biāo)準(zhǔn)化
- Getting Started with tmux
- INSTANT Social Media Marketing with HootSuite
- Architecting Data:Intensive Applications
- Hands-On Cloud:Native Microservices with Jakarta EE
- 智慧的物聯(lián)網(wǎng):感知中國(guó)和世界的技術(shù)