I am trying to write a test in Selenium, but for some reason my wdwait line of code in below method is failing with error message in title. When I comment the wdwait line, test passes normally. What am I missing?
One thing worth mentioning... in the same test, I have almost identical method for quantity dropbox and here wdwait works just fine. Both of the dropboxes are of the same "Select" type.
searchBoxDropdown is dropdown on amazon.com homepage next to the search bar
@FindBy(id="searchDropdownBox")
WebElement searchBoxDropdown;
public void selectDropdownElement(String elementx) {
wdwait.until(ExpectedConditions.elementToBeClickable(searchBoxDropdown));
Select elementDropdown = new Select(searchBoxDropdown);
elementDropdown.selectByVisibleText(elementx);
}
@Test
public void amazonTest() {
amazonAddToCart.selectDropdownElement("Books");
amazonAddToCart.inputSearchBox("Six of Crows Boxed Set");
amazonAddToCart.clickBookLink();
amazonAddToCart.selectHardcover();
amazonAddToCart.selectQuantity(20);
amazonAddToCart.clickGiftCheckbox();
amazonAddToCart.clickAddToCart();
}
<select aria-describedby="searchDropdownDescription" class="nav-search-dropdown searchSelect nav-progressive-attrubute nav-progressive-search-dropdown" data-nav-digest="k+fyIAyB82R9jVEmroQ0OWwSW3A=" data-nav-selected="0" id="searchDropdownBox" name="url" style="display: block; top: 2.5px;" tabindex="0" title="Search in">
I tried changing the method "elementToBeClickable" to "visibilityOfElements" but result was the same. Is there any similar method that allows WebElement to be selected that I could use maybe?
This solution is working the way I imagined:
public void selectDropdownElement(String elementx) {
wdwait.until(ExpectedConditions.textToBePresentInElement(searchBoxDropdown, "All"));
Select elementDropdown = new Select(searchBoxDropdown);
elementDropdown.selectByVisibleText(elementx);
}