WebDriver getText throws exceptions WebDriver getText throws exceptions selenium selenium

WebDriver getText throws exceptions


Instead of doing this:

getDriver().findElement(By.xpath("//span[text()='"+auctionID+"']"));

I would try something like this:

By auctionList = By.xpath(".//span[contains(@id,'listOfAuctions')]"));By containsTextWithId = By.xpath(".//span[contains(.,'" + id + "')]"));By combinedLocator = new ByChained(auctionList, containsTextWithId);

Or some similar idea, depending on what you are doing.


Instead of using getText(), in many occasions it's better to call getValue(). Using the getValue you might get a longer string, but the text you are expecting inside should be there.