Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 12th, 2012  |  syntax: None  |  size: 0.53 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. how can I check if some text exist or not in the page?
  2. List<WebElement> list = driver.findElements(By.xpath("//*[contains(text(),'" + text + "')]"));
  3. Assert.assertTrue("Text not found!", list.size() > 0);
  4.        
  5. String bodyText = driver.findElement(By.tagName("body")).getText();
  6. Assert.assertTrue("Text not found!", bodyText.contains(text));
  7.        
  8. bodyText = self.driver.find_element_by_tag_name('body').text
  9.        
  10. self.assertTrue("the text you want to check for" in bodyText)
  11.        
  12. driver.getPageSource().contains("Text which you looking for");