我需要檢查找到的鏈接是否包含<span >給定的文本。我找到鏈接的方式:
ExpectedConditions.elementToBeClickable(By.xpath("//a[@so-extra=\"x12fog\"]"))
怎么做?
uj5u.com熱心網友回復:
您可以使用findElementsXPath 定位器定義所需元素的方法,如下所示:
if(driver.findElements(By.xpath("//a[@so-extra='x12fog']//span[@class='extra-light' and contains(.,'stackoverflow')]")).size()>0){
System.out.println("Element found");
}
findElements方法回傳找到的匹配元素的串列。因此,如果存在這樣的元素,則串列將非空(大小> 0),否則回傳的串列將為空。
uj5u.com熱心網友回復:
嘗試任一xpath.
//a[.//span[@class='extra-light']]
或者
//a[.//span[@class='extra-light' and text()='stackoverflow']]
或者
//a[.//span[@class='extra-light' and contains(.,'stackoverflow')]]
代碼應該是
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light' and text()='stackoverflow']]"))
或者
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light' and contains(.,'stackoverflow')]]"))
或者
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light']]"))
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/515488.html
上一篇:表資料未回傳然后使用美湯
下一篇:以下代碼中的服務有什么問題?
