Java NoTouchElementException:无法在弹出窗口中找到元素
我已经切换到窗口弹出窗口,因为可以单击窗口弹出窗口中的按钮,但我无法找到单选按钮元素 这是我的代码:Java NoTouchElementException:无法在弹出窗口中找到元素,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我已经切换到窗口弹出窗口,因为可以单击窗口弹出窗口中的按钮,但我无法找到单选按钮元素 这是我的代码: driver.findElement(By.id("searchPrimIndustryImage")).click(); String mainWindow = driver.getWindowHandle(); Set<String> s1 = driver.getWindowHandles(); Iterator<String> i1 = s1.
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();
}
}
driver.findElement(By.id(“searchPrimIndustryImage”)。单击();
字符串mainWindow=driver.getWindowHandle();
Set s1=driver.getWindowHandles();
迭代器i1=s1.Iterator();
while(i1.hasNext())
{
字符串popupWindow=i1.next();
如果(!mainWindow.equalsIgnoreCase(popupWindow))
{
driver.switchTo()窗口(popupWindow);
driver.findElement(By.id(“Image1”))。单击();
findElement(By.xpath(“//input[@value='28049']))。单击();
driver.findElement(By.id(“Image5”))。单击();
}
}
单选按钮元素是带有xpath的元素。如果您确定xpath正确并且元素确实存在于页面上,请尝试使用waits。在单击xpath元素之前,请尝试添加以下内容:
WebDriverWait wait = new WebDriverWait(driver,30);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@value='28049']")));
你需要进口货
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.support.ui.ExpectedConditions;