I wanted to select option one by one from the drop down. But only first option is getting selected. my code is not able to select another option.
In below example, "Product Name: A to Z" is getting selected, but "Product Name: Z to A" is not getting selected. Please let me know if anybody aware of this issue.
This is HTML Source code:
<select id="selectProductSort" class="selectProductSort form-control">
<option value="position:asc">--</option>
<option value="price:asc" selected="selected">Price: Lowest first</option>
<option value="price:desc">Price: Highest first</option>
<option value="name:asc">Product Name: A to Z</option>
<option value="name:desc">Product Name: Z to A</option>
<option value="quantity:desc">In stock</option>
<option value="reference:asc">Reference: Lowest first</option>
<option value="reference:desc">Reference: Highest first</option>
</select>
This is my code trying to select two options one after another:
WebElement fieldSortBy = driver.findElement(By.id("selectProductSort"));
Select selectSortBy = new Select(fieldSortBy);
fieldSortBy.click();
selectSortBy.selectByVisibleText("Product Name: A to Z");
Thread.sleep(3000);
fieldSortBy.click();
selectSortBy.selectByVisibleText("Product Name: Z to A");
I am getting below exception:
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document