How can I add 'starts-with' or 'contains' for
(By.xpath("//ul/li[1]")));
something like
(By.xpath("//ul/li[1][contains(text(),'"+textConstant+"')]")));
which doesn't work
Can anyone assist with the proper formatting for this? Thanks
How can I add 'starts-with' or 'contains' for
(By.xpath("//ul/li[1]")));
something like
(By.xpath("//ul/li[1][contains(text(),'"+textConstant+"')]")));
which doesn't work
Can anyone assist with the proper formatting for this? Thanks
If Only one li tag contains that text then no need to mention index.
You can write like this:
By locator = By.xpath("//ul/li[contains(., '"+lostText+"')]");
WebElement errorFind = (new WebDriverWait(mypackage.ClassMain.driver, 15)).until(ExpectedConditions.presenceOfElementLocated(locator));
String text = mypackage.ClassMain.driver.findElement(By.xpath("//ul/li[1]")).getText();
if(text.equals("Lose") {
doNext();
} else {
System.out.print("Win \n");
doOther();
}
If textConstant is coming inside li tag, then you can write in following manner:-
(By.xpath("//ul/li[contains(.,'"+textConstant+"')]));
here, dot . stands for text()
You can use the AND operator for the Xpath.
//ul/li[position()=1 and contains(text(),'"+textConstant+"')]
This will match the top most li tagwhich contains the text constant value.