0

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.)

 driver.findElement(By.xpath(".//*[@id='content']/div[4]/ul[3]/li[2]/a")).click(); 

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

    while(i1.hasNext())         
    {       
        String ChildWindow=i1.next();       

                // Switching to Child window
                driver.switchTo().window(ChildWindow);
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                String vendorName=driver.findElement(By.id("vendorRqName")).getText();
                System.out.println(vendorName);
2
  • 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 '17 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 '17 at 11:02
0

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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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