Log4j logger — MultiLine Issue


Hello Friends,

I am working on log4j and was trying to print the menu bar text in the logs (Log4j logger), I was success but all the data are displaying with logs prefix.

Expected: getText() should display in single line. Using Log4j.

Smaple url: http://www.myntra.com   – – Myntra home page menu bar text I am displaying.

Logs sample:
2014-12-12 22:47:12,444 INFO [Logs] GetTitle is Captured
2014-12-12 22:47:12,493 INFO [Logs] GetText is Performed And the Texts are below:
2014-12-12 22:47:12,520 INFO [Logs] HOME
2014-12-12 22:47:12,545 INFO [Logs] MEN
2014-12-12 22:47:12,575 INFO [Logs] WOMEN
2014-12-12 22:47:12,600 INFO [Logs] KIDS
2014-12-12 22:47:12,654 INFO [Logs] PREMIUM
2014-12-12 22:47:12,691 INFO [Logs] LOOK GOODTRENDS
2014-12-12 22:47:12,714 INFO [Logs] GOSF – DEALS

But I want to print the result logs in ONE LINE.

For ex :

2014-12-12 22:47:12,520 INFO [Logs] HOME, MEN , WOMEN,…….. ETC.

Below is the sample method:

public static WebElement text_GetText(WebDriver driver){

WebElement ele =driver.findElement(By.className("navbar"));

List<WebElement>list = ele.findElements(By.tagName("a"));

Log.info("GetText is Performed And the Texts are below: ");

for(WebElement lists:list){

String list1=lists.getText();



}catch (Exception e){

Log.error("==> GetText is NOT Performed");



return element;


Train Asked on December 12, 2014 in Selenium WebDriver.
Add Comment
  • 1 Answer(s)
    Best answer

    Use this:

     String sList;
     for(WebElement lists:list){
              sList=sList + ", " + lists.getText();

    Lakshay Sharma

    Professor Answered on December 15, 2014.

    Up-voted and Bit edited, try this @Selenium.

    String sList="";
    for(WebElement lists:list){
    sList=sList + ", " + lists.getText();
    on December 16, 2014.
    Add Comment
  • Your Answer

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