How To Verify Multiple Line Text Containing Web Element …Please Provide Code in Java

I want to verify
“Connect With Friends and the
World  Around You On Facebook.”

I am using newline character “\n” within string  but its not working….please Provide solution with Code in Java

Train Asked on August 27, 2014 in Selenium WebDriver.
Add Comment
  • 2 Answer(s)

    Hi jogesh,

    You can follow the method given below. Hope it will work.

    The standard for defining a multi -line String literal in both Scala and Groovy is three double quotes. The syntax is:

    Regards,
    Vaidy

    Doctor Answered on August 28, 2014.

    hi vaidy
    can you give the exact solution as i am also trying to do it but no positive results yet..

    thanx
    ankit

    on August 28, 2014.
    Add Comment

    hi yogesh

    I tried this and it worked

    package com.toolsqa.problems;

     
    import junit.framework.Assert;
    import org.junit.Test;
     import org.openqa.selenium.By;
     import org.openqa.selenium.WebDriver;
     import org.openqa.selenium.firefox.FirefoxDriver;
    public class Testfb
    {WebDriver driver;
     @Test
     public void testtext()
     {
     String expected="Connect with friends and the\nworld around you on Facebook.";
    driver=new FirefoxDriver();
     driver.get("https://www.facebook.com/");
    String  text= driver.findElement(By.xpath("//h1[@class='inlineBlock _3ma _6n _6s _6v']")).getText();
     System.out.println(text);
    System.out.println(text.trim());
     System.out.println(expected.trim());
    if(text.trim().equalsIgnoreCase(expected.trim()))
     {
     System.out.println("strings are equal");
     }
     }
    }
    

     

    There Must be Some Spacing Issue With your code

    let me Know If it works

    thanks
    ankit

    Vice Professor Answered on August 28, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.