We have a Div containing some hard coded text and span containing some dynamic text values (refer below HTML code for more understanding). The resultant Text is: 1
Before you attempt to extract the total text e.g. 1 Tasks to be updated from 'XYZ' to 'ABC' you can induce WebDriverWait for all the three child elements to be visible and you can use the following solution:
new WebDriverWait(driver, 10).until(ExpectedConditions.and(
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='taskCountSpan']")),
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='oldStatusSpan']")),
ExpectedConditions.visibilityOfElementLocated(By.xpath("//span[@id='newStatusSpan']"))
));
You can use the Webelement.getText()
method to extract text and you can get the expected result as below
String actual =driver.findElement(By.id("bulk_update_confirmation")).getText();