0
votes

I am trying to code in java using selenium webdriver to click on Dropdown list in walmart page. But I am unable to access the li elements.

<button class="js-flyout-toggle dropdown" aria-haspopup="true" type="button" data-cat-id="0" aria-expanded="false"> All </button>
<div class="js-flyout-modal flyout-modal">
<ul class="block-list">
<li><button class="no-margin font-semibold" type="button" data-cat-id="0" tabindex="-1"> All Departments </button></li>
<li><button class="no-margin font-semibold" type="button" data-cat-id="91083" tabindex="-1"> Auto & Tires </button></li>
<li><button class="no-margin font-semibold" type="button" data-cat-id="5427" tabindex="-1"> Baby </button></li>

I wanted to access Baby using selenium webdriver in Java. Below is my code:

driver.get("http://www.walmart.com");
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement dropdown = driver.findElement(By.xpath("html/body/div[2]/header/div[3]/div/div/div/div/div[3]/form/div/div[1]/div/button"));
dropdown.click();
List<WebElement> liElements = driver.findElements(By.xpath("//*[@class='block-list']/li"));
for ( WebElement we: liElements) { 
    System.out.println(we.getText());           
            }

But this gives an error as below:-

"Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 132 milliseconds".

Please help

3
Try this: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);. Look at official doc seleniumhq.org/docs/04_webdriver_advanced.jspcsharpfolk
thanks will try thisUNG

3 Answers

0
votes

You defined WebDriverWait but you don't use it

WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement dropdown = wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("dropdown")));

Implicit wait will wait for element to exist in the DOM. If you want to use explicit wait you need to use Expected Conditions as well. Only defining WebDriverWait doesn't actually do anything.

0
votes

Your code looks fine. Please try below xpath :-

//div[@class='js-flyout-modal flyout-modal']//ul[@class='block-list']/li

Now first try to put thread.sleep if it works then it is problem of wait only

Thread.sleep(30000);

But then don't use Thread for your script as it's not recommended .. It's just to ensure that script is failing because of time

Hope it will help you :)

0
votes

May be other element in walmart page match your xpath //*[@class='block-list']/li and that element is not visible.