[英]How to check href of an element found using xpath contains text()
我試圖通過包含的文本查找元素,然后檢查該元素是否也有指向特定位置的鏈接。 我正在使用selenium / java。
我正在嘗試按文本查找元素,以盡可能減少如果更新UI時需要進行多少更改(減少測試維護成本)。
我嘗試了以下操作,但是斷言失敗,因為getAttribute最終為null。
WebElement newsHeadlineTemplate = driver.findElement(By.xpath("//*[contains(text(), 'News Headline')]"));
Assert.assertEquals("Template not clickable", "/news/create/new", newsHeadlineTemplate.getAttribute("href"));
我要查找/使用的元素的HTML:
<div class="columns">
<div class="column is-one-third">
<p>News Headline</p>
<a href="/news/create/new"></a>
</div>
</div>
我對硒還很陌生,因此非常感謝您的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.