0

I use selenium webdrive to select an item in a drop down list.

enter image description here

enter image description here

I want to click on "game club" element

I have tried few elements, but I get an error that non of them is clickable.

org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (790, 227). Other element would receive the click: <div id="select2-drop-mask" class="select2-drop-mask" style=""></div>
(Session info: chrome=41.0.2272.3)

However, using the browser I click on the item for sure.

How can I click on this item?

Elad Benda
  • 35,076
  • 87
  • 265
  • 471

2 Answers2

0

If this is a static list I would use the SelectElement(IWebElement element) method.

C# Example:

  var dropDown = _webDriver.FindElement(By.ClassName("select2-result-sub"));
  var dropDownSelector = new SelectElement(dropDown);
  dropDownSelector.SelectByIndex(3);
Jamie Rees
  • 7,973
  • 2
  • 45
  • 83
0

you can try:

public void click( By element ) {
    WebElement button = driver.findElement( element );
    try {
        button.click();
    } catch ( WebDriverException e ) {
        List<WebElement> availables = button.findElements( By.tagName( "div" ) );
        availables.addAll( button.findElements( By.tagName( "span" ) ) );
        tryClick( availables );
    }
}

public void tryClick( List<WebElement> availables ) {
    for ( WebElement candidate : availables ) {
        try {
            candidate.click();
            return;
        } catch ( WebDriverException e ) {
            continue;
        }
    }
}

after that use(for example):

click(By.id("elementId"));

regards!