power_settings_new

I am unable to run webdriver java cucumber automation script on Linux platform.

 

it say

  org.openqa.selenium.StaleElementReferenceException: Element is no longer attached to the DOM
      Command duration or timeout: 1.33 seconds
      For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
 
 
Please let me know if any concrete solution for this
 
I am using 2.53.0 for firefox 46.0 version on Linux environment.
 
Script works fine on Windows
 
Thnks
Anand
by (171 points)
Hi Anand,

StaleElementReferenceException usually occurs when an element is removed. E.g. You are running into the loop. During that one of the element is removed. In that case you will face above exception.

Can you post part of your code and at what point you are getting above error? It will be easy to point that out.
by
Well it is a Cucumber WebDriver in Java

Here is the below code

@And("^I enter my Return Dates as \"([^\"]*)\" days from today date$")
    public void i_enter_my_Return_Dates_as_days_from_today_s_date(int duration) throws ParseException {
        homescreenpage().enterReturnDate(duration);
    }


public void enterReturnDate(int duration) throws ParseException {

        Calendar rightNow = Calendar.getInstance();
        rightNow.add(Calendar.DAY_OF_MONTH, duration);

        day = rightNow.get(Calendar.DAY_OF_MONTH);
        month = rightNow.get(Calendar.MONTH);
        year = rightNow.get(Calendar.YEAR);
        String StringHomePagereturndate = day + "/" + (month + 1) + "/" + year;
        HomePagereturndate = StringToDate(StringHomePagereturndate);
        travelMonth = months[month] + " " + year;
        waitForElementVisible(ReturnDate, 5);
        click(ReturnDate);
        selectMonth(travelMonth);
        selectDay(travelMonth, day);

    }



public void selectMonth(String monthtobeSelected) {
        /*
         * Checking whether the Month and year we are going to select is same as
         * what is calculated
         */
        // System.out.println(getText(HomePage.xpathMonthYearSection));
        while (!getText(xpathMonthYearSection)
                .equals(monthtobeSelected)) { /*
                                                 * Keep executing untill month
                                                 * and year is not same as Month
                                                 * and year is calculated
                                                 */

            if (getText(xpathMonthYearRightSection).contains(months[month])
                    && getText(xpathMonthYearSection).contains(String.valueOf(year))) {
                returnTable = 2;
                break;
            } else {

                returnTable = 1;
                click(forwardArrow);/*
                                     * Keep clicking the forward button untill
                                     * selected month and year is not appeared
                                     */
            }
        }
    }


public static String getText(By selector) {
        waitUntillElementIsLocated(selector, 10);
        return find(selector).getText();

    }

Hope you can follow it otherwise I am happy to explain this.

Thank you
Anand Jois
by (171 points)
Which point you're getting the error? Also, a brief explanation will help me resolve your issue very fast.
by
return find(selector).getText();

This above line has the issue.

I have added waitTill element visible but still no clue

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

1 Answer

by (171 points)
0 votes

It looks like you're using absolute xpath for xpathMonthYearSection and other xpaths.

Some times xpath may be different for different OS and browser combination . Try using relative xpath or use css selector. 

Let me know the output.

by
Hi Mayur,

I am using xpaths as well as cssSelector but unfortunately not working for both. I can try for absolute and see .

Will update u soon
by
Below are the xpath formats I am using

public static final By overseas = By.xpath("//*[@class='header-menu unified-menu']/li[1]/ul/div/li[1]/a");
    public static final By AnnualMultiTrip = By.xpath("//*[@class='header-menu unified-menu']/li[1]/ul/div/li[2]/a");
    public static final By Cruise = By.xpath("//*[@class='header-menu unified-menu']/li[1]/ul/div/li[3]/a");
    public static final By Domestic = By.xpath("//*[@class='header-menu unified-menu']/li[1]/ul/div/li[4]/a");

It should work. Or any standards to be used because same xpaths work on windows but not on Linux

Thanks
Anand Jois
by (171 points)
That again depends on your page renders on the particular operating system and browser combination. Usually applications are developed in such a way that it renders the same way on all browsers and OS combinations. If your application is developed in such a way that it renders differently for different OS combinations, you will have to use the OS specific element.

Also post your code of "find(selector)".
add
...