Note that there are some explanatory texts on larger screens.

plurals
  1. POwebdriver - verify text presentation on a loaded page
    primarykey
    data
    text
    <p>I am trying to verify a line of text is present on a loaded page using webdriver. I created a <strong>function - isTextPresent</strong>, then invoked the function within the same method. </p> <p>Eclipse prompted me the error: <strong>the method IsTrue(boolean) is undefined for the type Assert</strong>.</p> <ol> <li>Please tell me why it doesn't work and how should I fix it. </li> <li><p>whatis the best approach to verify the text presentation on a web page?</p> <p>2a. is it possible to verify the text presentation within the first <code>@Test</code> code fragment?</p> <p>2b. which type## Heading ## of method shall I use in this case (public, private or protected)?</p></li> </ol> <p>My code fragment: </p> <pre class="lang-java prettyprint-override"><code>import java.util.List; import java.util.concurrent.TimeUnit; import org.junit.*; import org.junit.Before; import org.junit.After; import org.openqa.selenium.*; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; public class selftechyTestng { private WebDriver driver; private String baseUrl; @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "http://selftechy.com/"; driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); } //First Test Method @Test public void searchElements() throws Exception{ driver.get(baseUrl); driver.findElement(By.xpath("//a[@title='Selenium']")).click(); } @Test public boolean isTextPresent(String txtValue){ try{ boolean b = driver.getPageSource().contains(txtValue); return b; } catch (Exception e){ return false; } Assert.IsTrue(isTextPresent("TestNG (Next Generation Testing Framework) – Understanding Annotations")); } } </code></pre> <p>Modification I have done to make the call to the function <strong>isElementPresent</strong> work Adding assertTrue() method within <strong>searchElements()</strong> methods</p> <pre><code> assertTrue(isTextPresent(txtValue)); </code></pre> <p>Method isElementPresent</p> <pre><code>public boolean isTextPresent(String str1) { try { driver.get(baseUrl); driver.findElement(By.xpath("//a[@title='Selenium']")).click(); b = driver.getPageSource().contains(str1); if(b){ System.out.println("text presented on the page"); } else{ System.out.println("text did not present on the page"); } return b; } catch (Exception e) { System.out.println(e.getMessage()); return b; } //return b; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload