0

Following code isn't working. Please help.

        WebElement output=driver.findElement(By.id("XLEW_1_3_1"));

        System.out.print (output.getText());    
        if (output.getText()=="4")
        {

            System.out.print("Correct output");
        }
        else
        {
            System.out.print("Incorrect output");

        }
4
2

Try the below code, its working fine for the sample given

driver.get("https://ssccust1.spreadsheethosting.com/1/59/226a21cef25ec5/for_automation/for_automation.htm");
        driver.findElement(By.id("XLEW_1_1_1")).sendKeys("4"+Keys.TAB);
        String output=driver.findElement(By.id("XLEW_1_3_1")).getAttribute("value");
        Thread.sleep(1000);
        if (output.equals("4"))
        {

            System.out.print("Correct output");
        }
        else
        {
            System.out.print("Incorrect output");

        }
3
  • Thanks a lot. But why do we need to do "sendKeys("4"+Keys.TAB)"? There are two input fields. I have entered 2 in both fields. So, the output will be 4 because i have applied sum formula. All I need to test if the output is 4 or not? – Shama Shakya Oct 1 '18 at 8:46
  • Thank you so much. It worked. There was a problem with Threadsleep. Much appreciated. :) – Shama Shakya Oct 1 '18 at 9:09
  • @shama for testing I have Given tab,you can remove the "Tab" key – Vel Guru Oct 1 '18 at 11:21

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.