mercredi 8 mars 2017

Selenium Webdriver getText(): Check only for appearence of a numeric value

I am trying to automate a workflow with a Submit button using Selenium in Eclipse.

I am using a custom function 'waitForVisible' to check if the WebElement with id 'naviInfo' is displayed and if it holds a message having either 'No rows were found' or '{number} rows were found' message.

The problem is I am unable to sort and check the numeric part of the text. Example code given below.

if ("No rows were found".equals(waitForVisible(By.id("naviInfo")).getText()))
{
      log.info("No rows were found after submit");
}
else if ("**1804** rows were found".equals(waitForVisible(By.id("naviInfo")).getText()))
{
      log.info("**1804** rows found after submit");
}
else
{
      (other error checks)
}

How do I just check if there is a numeric value found before the common text ' rows were found'? Additionally also save this number to a variable?

Aucun commentaire:

Enregistrer un commentaire