How to extract dynamic text from multiple child nodes within the html through getText()

前端 未结 2 1718
轮回少年
轮回少年 2020-12-12 00:56

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

相关标签:
2条回答
  • 2020-12-12 01:18

    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']"))
    ));
    
    0 讨论(0)
  • 2020-12-12 01:21

    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();
    
    0 讨论(0)
提交回复
热议问题