- 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ò)基礎(chǔ)與設(shè)備
- 6G潛在關(guān)鍵技術(shù)(下冊(cè))
- 從區(qū)塊鏈到Web3:構(gòu)建未來互聯(lián)網(wǎng)生態(tài)
- 工業(yè)控制網(wǎng)絡(luò)安全技術(shù)與實(shí)踐
- 新一代物聯(lián)網(wǎng)架構(gòu)技術(shù):分層算力網(wǎng)絡(luò)
- WordPress 5 Complete
- Spring Cloud微服務(wù)架構(gòu)進(jìn)階
- 網(wǎng)絡(luò)安全技術(shù)與解決方案(修訂版)
- Wireshark網(wǎng)絡(luò)分析就這么簡單
- TD-LTE無線網(wǎng)絡(luò)規(guī)劃與設(shè)計(jì)
- 紅藍(lán)攻防:構(gòu)建實(shí)戰(zhàn)化網(wǎng)絡(luò)安全防御體系
- 物聯(lián)網(wǎng)場(chǎng)景設(shè)計(jì)與開發(fā)(初級(jí))
- 數(shù)據(jù)血緣分析原理與實(shí)踐
- Enterprise ApplicationDevelopment with Ext JSand Spring
- 現(xiàn)場(chǎng)綜合化網(wǎng)絡(luò)運(yùn)營與維護(hù):運(yùn)營商數(shù)字化轉(zhuǎn)型技術(shù)與實(shí)踐