- 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.
- 計算機網(wǎng)絡(luò)與通信(第2版)
- Building Django 2.0 Web Applications
- 5G承載網(wǎng)網(wǎng)絡(luò)規(guī)劃與組網(wǎng)設(shè)計
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- Windows Server 2003 Active Directory Design and Implementation: Creating, Migrating, and Merging Networks
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- 2018網(wǎng)信發(fā)展報告
- Mastering TypeScript 3
- The Kubernetes Workshop
- jQuery Mobile Web Development Essentials
- 一本書讀懂物聯(lián)網(wǎng)
- bash網(wǎng)絡(luò)安全運維
- SEO攻略:搜索引擎優(yōu)化策略與實戰(zhàn)案例詳解
- 趣話通信:6G的前世、今生和未來
- INSTANT Social Media Marketing with HootSuite