0

I have the following code from SNAPDEAL, i want to select 1TB and 120 GB

<div class="filter-inner overflow-filter" data-name="Capacity_s">
    <div class="filters-list sdCheckbox  ">
        <input class="filter-value" type="checkbox" value="1 TB"> 
        <label for="Capacity_s-1 TB"> 
            <a class="filter-name hashAdded" href="https://www.snapdeal.com/products/storage-devices/filters/Capacity_s~1%20TB#bcrumbLabelId:3032">
            1 TB</a>
            <span class="filter-prod-count">20</span>
        </label>
    </div>
    <div class="filters-list sdCheckbox  ">
        <input class="filter-value" type="checkbox" value="120 GB"> 
        <label for="Capacity_s-120 GB"> 
            <a class="filter-name hashAdded" href="https://www.snapdeal.com/products/storage-devices/filters/Capacity_s~120%20GB#bcrumbLabelId:3032">
            120 GB</a>
            <span class="filter-prod-count">1</span>
        </label>
    </div>
</div>

Have written following code, it does select the first checkbox but however it doesn't selected remaining and there is an error

@FindBy(xpath = "//div[@class='filter-inner overflow-filter']/div") List<WebElement> list_elements;
SnapDeal sd = PageFactory.initElements(driver, SnapDeal.class);
        for ( WebElement el : sd.list_elements ) {
            if ( !el.isSelected() ) {
                el.click();
            }

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

Spholt
  • 3,724
  • 1
  • 18
  • 29
  • Does this answer your question? [stale element reference: element is not attached to the page document](https://stackoverflow.com/questions/18225997/stale-element-reference-element-is-not-attached-to-the-page-document) – Evgeniy Chiruk Jan 23 '20 at 12:49
  • Add a print statement above `el.click();` to see how many times it actually tries to click. – Jortega Jan 23 '20 at 13:21

0 Answers0