I need to check if located link contains <span >
with a given text.
The way I locate the link:
ExpectedConditions.elementToBeClickable(By.xpath("//a[@so-extra=\"x12fog\"]"))
How to make it?
CodePudding user response:
You can use findElements
method with XPath locator defining the desired element as following:
if(driver.findElements(By.xpath("//a[@so-extra='x12fog']//span[@class='extra-light' and contains(.,'stackoverflow')]")).size()>0){
System.out.println("Element found");
}
findElements
method return a list of found matching elements. So, if there is such element the list will be non-empty (size>0), otherwise the returned list will be empty.
CodePudding user response:
Try either of the xpath
.
//a[.//span[@class='extra-light']]
Or
//a[.//span[@class='extra-light' and text()='stackoverflow']]
Or
//a[.//span[@class='extra-light' and contains(.,'stackoverflow')]]
Code should be
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light' and text()='stackoverflow']]"))
Or
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light' and contains(.,'stackoverflow')]]"))
or
ExpectedConditions.elementToBeClickable(By.xpath("//a[.//span[@class='extra-light']]"))