Stale element reference on selecting checkout date in Airbnb site

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Stale element reference on selecting checkout date in Airbnb site

Savan Rai
Stale element reference on selecting checkout date in Airbnb site.

I am able to select checkin date.But stale element error is encountered on selection of checkout date.
Please help in fixing this issue.

Code:

package test.java.tests;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {
 public static void main(String[] args){
     
    System.setProperty("webdriver.chrome.driver", "/Users/savanrai/Documents/Jars/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.airbnb.com.sg/a");   
    driver.manage().window().fullscreen();   
    driver.findElement(By.id("checkin_input")).click();   
    List<WebElement> date = driver.findElements(By.xpath("//div[@class='_1lds9wb']//div[@class='_gahfr9']//table[@class='_p5jgym']//td"));
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("7")){
            date.get(j).click();
        }
    }
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("8")){
            date.get(j).click();
        }
    }
 }
}


Error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/34c3f971-56e0-4e4d-8da3-b97dc6bcb24e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Stale element reference on selecting checkout date in Airbnb site

Xiang Dong
Get a sleep or wait for a while and reallocate the element. DOM get changed from your previous action. It is normal when you try to play action in an iteration.

Best Regards,
--david

From: [hidden email] <[hidden email]> on behalf of Savan Rai <[hidden email]>
Sent: Sunday, April 1, 2018 8:30 PM
To: Selenium Users
Subject: [selenium-users] Stale element reference on selecting checkout date in Airbnb site
 
Stale element reference on selecting checkout date in Airbnb site.

I am able to select checkin date.But stale element error is encountered on selection of checkout date.
Please help in fixing this issue.

Code:

package test.java.tests;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {
 public static void main(String[] args){
     
    System.setProperty("webdriver.chrome.driver", "/Users/savanrai/Documents/Jars/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.airbnb.com.sg/a");   
    driver.manage().window().fullscreen();   
    driver.findElement(By.id("checkin_input")).click();   
    List<WebElement> date = driver.findElements(By.xpath("//div[@class='_1lds9wb']//div[@class='_gahfr9']//table[@class='_p5jgym']//td"));
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("7")){
            date.get(j).click();
        }
    }
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("8")){
            date.get(j).click();
        }
    }
 }
}


Error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/34c3f971-56e0-4e4d-8da3-b97dc6bcb24e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/SN1PR12MB034944810E99B9C295245AF390A60%40SN1PR12MB0349.namprd12.prod.outlook.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Stale element reference on selecting checkout date in Airbnb site

Vishal Kumar
In reply to this post by Savan Rai

Hi,

Code:

package test.java.tests;

import java.util.List;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {
 public static void main(String[] args){
     
    System.setProperty("webdriver.chrome.driver", "/Users/savanrai/Documents/Jars/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.airbnb.com.sg/a");    
    driver.manage().window().fullscreen();    
    driver.findElement(By.id("checkin_input")).click();    
    List<WebElement> date = driver.findElements(By.xpath("//div[@class='_1lds9wb']//div[@class='_gahfr9']//table[@class='_p5jgym']//td"));
WebDriverWait wait=new WebDriverWait(driver, 40);
wait.until(ExpectedConditions.visibilityOfAllElements(date));
    
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("7")){
            date.get(j).click();
        }
    }
    
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("8")){
            date.get(j).click();
        }
    }
 }
}

Use this one, i hope this will be work.

Thanks,
Vishal

On Sun, Apr 1, 2018 at 6:00 PM, Savan Rai <[hidden email]> wrote:
Stale element reference on selecting checkout date in Airbnb site.

I am able to select checkin date.But stale element error is encountered on selection of checkout date.
Please help in fixing this issue.

Code:

package test.java.tests;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {
 public static void main(String[] args){
     
    System.setProperty("webdriver.chrome.driver", "/Users/savanrai/Documents/Jars/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("https://www.airbnb.com.sg/a");   
    driver.manage().window().fullscreen();   
    driver.findElement(By.id("checkin_input")).click();   
    List<WebElement> date = driver.findElements(By.xpath("//div[@class='_1lds9wb']//div[@class='_gahfr9']//table[@class='_p5jgym']//td"));
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("7")){
            date.get(j).click();
        }
    }
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("8")){
            date.get(j).click();
        }
    }
 }
}


Error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/34c3f971-56e0-4e4d-8da3-b97dc6bcb24e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAB-Tc54mBY3N42nPveEuUFkxZ1u_y31%2BjhjF89drQ8sCV-Dh1w%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Stale element reference on selecting checkout date in Airbnb site

Magesh N
In reply to this post by Savan Rai
Just reinitialize the element which throws stale element

On Sunday, April 1, 2018 at 7:29:51 PM UTC+5:30, Savan Rai wrote:
Stale element reference on selecting checkout date in Airbnb site.

I am able to select checkin date.But stale element error is encountered on selection of checkout date.
Please help in fixing this issue.

Code:

package test.java.tests;

import java.util.List;

import <a href="http://org.openqa.selenium.By" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Forg.openqa.selenium.By\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEfZQPnvt4Ug_Aq50kJ-TWrQ8CZyg&#39;;return true;">org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class DatePicker {
 public static void main(String[] args){
     
    System.setProperty("webdriver.chrome.driver", "/Users/savanrai/Documents/Jars/chromedriver");
    WebDriver driver = new ChromeDriver();
    driver.get("<a href="https://www.airbnb.com.sg/a" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.airbnb.com.sg%2Fa\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHU-SVuxa8t2Qpxi2UEJSm-y6PiLw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Fwww.airbnb.com.sg%2Fa\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHU-SVuxa8t2Qpxi2UEJSm-y6PiLw&#39;;return true;">https://www.airbnb.com.sg/a");   
    driver.manage().window().fullscreen();   
    driver.findElement(By.id("checkin_input")).click();   
    List<WebElement> date = driver.findElements(By.xpath("//div[@class='_1lds9wb']//div[@class='_gahfr9']//table[@class='_p5jgym']//td"));
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("7")){
            date.get(j).click();
        }
    }
   
    for(int j=0;j<date.size();j++){
        String dateFrom = date.get(j).getText();
        System.out.println(dateFrom);
        if(dateFrom.equals("8")){
            date.get(j).click();
        }
    }
 }
}


Error:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=65.0.3325.181)
  (Driver info: chromedriver=2.35.528157 (4429ca2590d6988c0745c24c8858745aaaec01ef),platform=Mac OS X 10.13.3 x86_64) (WARNING: The server did not provide any stacktrace information)

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/09c76fbd-7eaa-46b4-8338-0cec03516302%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.