0
if(!"".equals(MyFrnds.list_Friends))
        {
            System.out.println("There is friends list");

            Actions action= new Actions(driver);
            action.contextClick(MyFrnds.list_Friends).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
            System.out.println("My first friend link is opened in new tab and clicking on Show more button if there are more than 12 friends ");
            if(!"".equals(MyFrnds.list_Friends))
            {
             MyFrnds.btn_FrShowmore.click();
            }else
            {
                System.out.println("There are no more than 12 records");
            }
        }

        else
        {
            System.out.println("There are no friends to display.  So clicking on these two links to add friends");

            // Right on FITBASE MEMBERS link and open in new tab
        Actions action= new Actions(driver);
        action.contextClick(MyFrnds.lnk_Fitbasemem).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
            // Right on Social network link and open in new tab
        action.contextClick(MyFrnds.lnk_Socialnet).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.RETURN).build().perform();
        }

In the above code on very first line I gave If condition as (!"".equals(MyFrnds.list_Friends)) but irrespective of the application it goes to first part of the condition even though it doesn't satisfy the first condition. Hence we get error in executing the script. Can anyone suggest what is wrong in the code.

  • what does MyFrnds.list_Friends returns? Is it a string or list? If list then check condition if(MyFrnds.list_Friends.size()>0)....else.... – Deepak Aug 04 '15 at 06:22

1 Answers1

1

!"".equals(MyFrnds.list_Friends) is true if MyFrnds.list_Friends is not an empty string. For example if MyFrnds.list_Friends is null, the condition would also return true. You may want to perform an additional null check or simply use StringUtils.isNotBlank(MyFrnds.list_Friends).

Java, check whether a string is not null and not empty?

Community
  • 1
  • 1
Sebastian
  • 5,721
  • 3
  • 43
  • 69