NoSuchElementException: Unable to locate element in popup window

Fatin Shafiqah :

I already switched to the window pop up because the button in the window popup can be clicked, but I'm unable to locate the radio button element.

This is my code:

driver.findElement(By.id("searchPrimIndustryImage")).click();

String mainWindow = driver.getWindowHandle();

    Set<String> s1 = driver.getWindowHandles();
    Iterator<String> i1 = s1.iterator();
    while(i1.hasNext())
    {
        String popupWindow = i1.next();
        if(!mainWindow.equalsIgnoreCase(popupWindow))
        {
            driver.switchTo().window(popupWindow);
            driver.findElement(By.id("Image1")).click();
            driver.findElement(By.xpath("//input[@value='28049']")).click();
            driver.findElement(By.id("Image5")).click();
        } 
    }

The radio button element is the one with the xpath.

Mate Mrše :

If you are sure the xpath is correct and the element is really present on the page, try using waits. Try adding this before clicking the xpath element:

WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='28049']")));

You will need the imports

import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=106461&siteId=1