Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

1 like 0 dislike
385 views
by

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 The go-to Tester (181 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 The go-to Tester (181 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

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)

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 The go-to Tester (181 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)".


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...