I have a scenario where it is needed to verify the text that is manually input ina a text box of a sub window by storing and then printing it. But nothing happens and eclipse just shows as running. (I have used the sleep command to get the delay to enter the data.)


    // To handle all new opened window.             
        Set<String> s1=driver.getWindowHandles();       
    Iterator<String> i1=s1.iterator();      

        String ChildWindow=i1.next();       

                // Switching to Child window
                try {
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block

                String vendorName=driver.findElement(By.id("vendorRqName")).getText();
  • 1
    What makes you think there is issue with System.out.println ? Write it like this System.out.println("Vendor name is " + vendorName); to verify whether print works, its more likely that getText() returns just empty string
    – George
    Aug 23, 2017 at 9:15
  • If it is in a input box, should youn't use getAttribute("value") instead of getText()? Please post the htmk code.
    – Patrick
    Aug 23, 2017 at 11:02

1 Answer 1


getText() is used only to get the text that is in the form of labels/Combobox. If there is a <p> tag and you want to get the contents in the <p> tag you can use getText() or if there is a key-value pair, you wanted to know the string in the "key" you can use getText(), but not inside a textbox/textarea. You must use the below code.

String vendorName=driver.findElement(By.id("vendorRqName")).getAttribute("value");

Also, using thread.sleep() is not recommended, use implicit/explicit waits.

Alternatively, you can use firepath in firebug to find whether the "id" exists. Write something else along with the vendorName string to make sure System.out.println is executed.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.