1

Trying to select a dropdown and select an item from the list.

Here is the dom for the dropdown.

<li id="nav-galleries" class="dropdown header-dropdown hidden-xs hidden-sm">

<a class="dropdown-toggle" 
href="//www.xxxx/" data-toggle="dropdown" 
title="Trending Now">
<span class="nav-text"> Trending Now </span>
<b class="caret"></b>

this is the code for the 'button' or 'link' that I am trying to hit.

<a href="/xxxxxx/members/content/videos/"> Videos </a>

I have the hover part done correctly. I can show the list and the items inside of it. When i try to do a click it usually tells the Element is not visible.

This is my code to try and click inside of it. It clicks on a link but it seems to just click on the middle of the dropdown, not on a specific array.

$action->moveToElement($this->webDriver->findElement(WebDriverBy::cssSelector('#nav-galleries')))->perform();
      $dropdown =  $this->webDriver->findElements(WebDriverBy::cssSelector('#nav-galleries .dropdown-menu'))[0];
      $dropdown->click();

When i try to change the click on the array, I'm met with Element not visible.

I've even tried some javascript to do the hover, which it does, yet i'm still met with element not visible when I try to select an option in the drop down.

$this->webDriver->executeScript("document.getElementsByClassName('dropdown-menu')[0].style.display='list-item'");

Any advice would be appreciated.

1

Selenium probably is trying to get the elements before the list is visible.

After the click, try to wait:

$driver->wait(10, 1000)->until(
  WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::cssSelector('#nav-galleries .dropdown-menu'))
);
  • 1
    Thanks I believe your line of code ended up helping. I did also go back and add an ID to the CSS Selector infront of the class to make it even more specific. $dropdown = $this->webDriver->findElement(WebDriverBy::cssSelector('#nav-galleries .dropdown-toggle')); $this->webDriver->wait(10, 1000)->until(WebDriverExpectedCondition::visibilityOfElementLocated(WebDriverBy::cssSelector('#nav-galleries .dropdown-menu'))); $dropdown->click(); Thanks bro. – Christian May 9 '17 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.