0

enter image description here


Below are the code which I used:

    driver.findElement(By.xpath("//div[@class=' flag-dropdown']")).click();
    WebDriverWait wait = new WebDriverWait(driver, 10);
    List<WebElement> options = driver.findElements(By.xpath("//ul[@role='listbox']/li"));
    By Country1 = By.xpath("//ul[@role='listbox']/li[85]");
    WebElement element1 = driver.findElement(Country1);
    Thread.sleep(1000);
    for (WebElement opt : options) {
        if (opt.equals(element1)) {
            WebElement element3 = null;
            element3 = wait.until(ExpectedConditions.presenceOfElementLocated(Country1));
            element3.click();   
        }
    }

My error is:

Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <li data-flag-key="flag_no_83" class="country" data-dial-code="1" tabindex="0" data-country-code="is" role="option">...</li> is not clickable at point (746, 276). Other element would receive the click: <input class="search-box" type="search" placeholder="search" autocomplete="off" value="">
  (Session info: chrome=92.0.4515.159)

and it scrolls to the required country but I'm unable to click it.
Can anyone help me with this?
3
  • What have you tried so far? Show us your code and point to the places where it does not work.
    – pavelsaman
    Aug 25, 2021 at 12:35
  • Please add this to the original question. Format the code. What error are you getting?
    – pavelsaman
    Aug 25, 2021 at 13:00
  • @pavelsaman I formatted the code, but couldn't find any error when I run my script and it failed to select the dropdown
    – QA stacker
    Aug 25, 2021 at 13:12

1 Answer 1

0

Sorry for you, but your error say that some other element hide the element you want to click on. Try this :

element3 = wait.until(ExpectedConditions.elementToBeClickable(Country1));

instead of

element3 = wait.until(ExpectedConditions.presenceOfElementLocated(Country1));

Many time some element hide yours, some times you should try by javascript solution

JavaScriptExecutor jsExec = (JavaScriptExecutor)driver;
jsExec.executeScript("arguments[0].scrollIntoView();", driver.findElement(country1));   
jsExec.executeScript("arguments[0].click();", driver.findElement(country1))

Hope this can help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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