- Selenium WebDriver 3 Practical Guide
- Unmesh Gundecha Satya Avasarala
- 181字
- 2021-08-13 16:08:08
The By.partialLinkText() method
The By.partialLinkText locating mechanism is an extension of the By.linkText locator. If you are not sure of the entire link text or want to use only part of the link text, you can use this locator to identify the link element. So, let's modify the previous example to use only partial text on the link; in this case, we will use Privacy from the Privacy Policy link in the site footer:

The code would look like this:
@Test
public void byPartialLinkTextLocatorExample() {
WebElement orderAndReturns =
driver.findElement(By.partialLinkText("PRIVACY"));
orderAndReturns.click();
assertThat(driver.getTitle())
.isEqualTo("Privacy Policy");
}
What happens if there are multiple links whose text has Privacy in it? That is a question for the findElement() method rather than the locator. Remember when we discussed the findElement() method earlier, it will return only the first WebElement that it comes across. If you want all the WebElements that contain Privacy in its link text, use the findElements() method, which will return a list of all those elements.
- 物聯(lián)網(wǎng)(IoT)基礎(chǔ):網(wǎng)絡(luò)技術(shù)+協(xié)議+用例
- 物聯(lián)網(wǎng)網(wǎng)絡(luò)安全及應(yīng)用
- SEO 20日
- GPS/GNSS原理與應(yīng)用(第3版)
- 電子政務(wù)效益的經(jīng)濟分析與評價
- 網(wǎng)絡(luò)創(chuàng)新指數(shù)研究
- 物聯(lián)網(wǎng)概論(第2版)
- Spring Cloud微服務(wù)架構(gòu)進階
- 大話社交網(wǎng)絡(luò)
- 區(qū)塊鏈輕松上手:原理、源碼、搭建與應(yīng)用
- Metasploit Penetration Testing Cookbook
- C/C++串口通信:典型應(yīng)用實例編程實踐
- 網(wǎng)絡(luò)基礎(chǔ)與網(wǎng)絡(luò)管理項目化教程
- Microservice Patterns and Best Practices
- 新手易學(xué):新手學(xué)淘寶開店