2

I'm programming selenium test-cases using eclipse. I want to test an online-shop and want to see if the functionality is right.

I want to test, if the number "785" is over 100 . There are lot of span-tags and a lot of sites, so I want to test it automatically.

Here is the code-snippet, I want to test.

<span class="left inline-block">Angezeigte Artikel: 1 bis 24 (von 785)</span>

I can find the span-tag with this code-snippet but I can't get the text and set a specific condition.

driver.findElement(By.tagName("span")).findElement(By.xpath("//div[contains(.,'von')]" )).getText();
Edd
  • 3,724
  • 3
  • 26
  • 33
Nazan
  • 23
  • 3

1 Answers1

1

Get the text from the span element, use regular expressions with saving groups to extract the desired value and cast it to int:

String text = driver.findElement(By.xpath("//span[contains(., 'von')]" )).getText();
Pattern p = Pattern.compile("\d+ bis \d+ \(von (\d+)\)$");
Matcher m = p.matcher(text);

if (m.find()) {
    int value = Integer.parseInt(m.group(1));
}
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195