0

enter image description hereenter image description here I have a dropdown structure with multiple options to select one below the other. The options remain same only the element to select changes. First element is been selected properly but when it goes for selecting the 2nd element, org.openqa.selenium.ElementNotInteractableException, TimeOutException are been given. Please guide me as I have stuck with my Automation code because of this issue.

I tried various things like JavaScriptExecutor, ExplicitWait etc but all in vain. The things that I tried are being commented in code. Also the xpath I used for first name '//li[@class='ant-select-dropdown-menu-item' and text()='First Name']' same when I use for Middle name,webdriver gives the Element not clickable Exception. Referred other questions related to Element Not Interactable in stack overflow but couldn't find the solution.

//Java Code List elements = driver.findElements(By.xpath("//*[@class='ant-select-arrow']")); for (int i=0; i div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//li[@class='ant-select-dropdown-menu-item' and text()='First Name']")).click();

        Thread.sleep(2000);
        try {
            //driver.findElement(By.cssSelector("div.ant-row:nth-child(2) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click();
            elements.get(1).click();
            Thread.sleep(5000);
            //WebDriverWait wait1=new WebDriverWait(driver,10);
            //wait1.untildriver.findElement(By.xpath("//li[@class='ant-select-dropdown-menu-item' and text()='Middle Name']"));
//          WebElement element1=wait1.until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div/ul/li[3]")));
//          element1.click();
            //WebDriverWait wt= new WebDriverWait(driver,10);
            //wt.until(ExpectedConditions.elementToBeClickable(By.cssSelector("body > div:nth-child(10) > div > div > div > ul > li:nth-child(3)"))).click();
            driver.findElement(By.cssSelector("body > div:nth-child(10) > div > div > div > ul > li:nth-child(3)"));


        }catch(Exception e) {
            e.printStackTrace();
        }

        Thread.sleep(3000);

        //driver.findElement(By.cssSelector("div.ant-row:nth-child(3) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click();
        elements.get(2).click();
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("body > div:nth-child(11) > div > div > div > ul > li:nth-child(4)")).click();


        Thread.sleep(2000);
        try {
            //          driver.manage().window().maximize();
            //          JavascriptExecutor jse = (JavascriptExecutor)driver;
            //          Thread.sleep(2000);
            //          jse.executeScript("window.scrollBy(0,250)", "");
            //Thread.sleep(2000);

            //driver.findElement(By.cssSelector("div.ant-row:nth-child(4) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click();
            elements.get(3).click();
            Thread.sleep(3000);
            //  new WebDriverWait(driver, 30).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("/html/body/div[4]/div/div/div/ul/li[5]")));
            driver.findElement(By.xpath("/html/body/div[7]/div/div/div/ul/li[5]")).click();
        }catch(Exception e) {
            e.printStackTrace();
        }



        Thread.sleep(2000);
        elements.get(4).click();
        //driver.findElement(By.cssSelector("div.ant-row:nth-child(5) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("/html/body/div[8]/div/div/div/ul/li[6]")).click();

        Thread.sleep(2000);
        elements.get(5).click();
        //driver.findElement(By.cssSelector("div.ant-row:nth-child(6) > div:nth-child(3) > div:nth-child(1) > div:nth-child(1) > span:nth-child(2)")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath("/html/body/div[9]/div/div/div/ul/li[7]")).click();

org.openqa.selenium.ElementNotInteractableException, TimeOutException are been given. Element cannot be scrolled into view error also is been given.
Pratik Pathare
  • 43
  • 1
  • 11

1 Answers1

0

Create separate web elements for each of the values in the dropdown. Then perform click event using Actions.

    WebElement Food = driver.findElement(By.xpath("//*[@id='main-menu']/div/ul/li[11]/a"));
    WebElement Drinks = driver.findElement(By.xpath("//*[@id='drinks']/span[1]"));
    WebElement RedBull = driver.findElement(By.xpath("//*[@id='redbull']/span[1]"));

Actions action = new Actions(driver);
action.moveToElement(Food).click().moveToElement(Drinks).click().build().perform();
Thread.sleep(200);
action.moveToElement(RedBull).click().build().perform();

Refer https://sqa.stackexchange.com/questions/38546/select-an-dropdown-element-selenium-java

Sugan
  • 447
  • 1
  • 4
  • 16
  • I tried this. elements.get(1).click(); WebElement Middle_Name=driver.findElement(By.xpath("//li[@class='ant-select-dropdown-menu-item' and text()='Middle Name']")); Actions action = new Actions(driver); action.moveToElement(Middle_Name).click().build().perform(); But giving the following exception. org.openqa.selenium.WebDriverException: TypeError: rect is undefined – Pratik Pathare Sep 11 '19 at 05:37