Friday, February 10, 2012

Webdriver - Retrieve innerHTML

Webdriver - Retrieve innerHTML

I was implementing an assertion for save transaction and was trying to retrieve the text using Gettext(), but not successful, getting null. Below is the HTML layout.

String Status = driver.findElement(By.id("spnSuccess")).getText();


Then I have implemented following JavaScript to retrieve the text.

     String script = "return document.getElementById('spnSuccess').innerHTML;";
    String Temp = (String) ((JavascriptExecutor) driver).executeScript(script);
    assertEquals(Temp,"Requisition Saved Successfully");

---



No comments:

Post a Comment