org.openqa.selenium.NoSuchElementException for IE11



这里是硒的新手,请耐心等待。

我在win7和InternetExplorer11上使用seleniumWebdriver 2.41.0,并得到以下"org.openqa.selenium.NoSuchElementException:找不到id=home_title的元素(警告:服务器没有提供任何堆栈竞争信息)"

我正在从属性文件中读取url和iedriverpath,当浏览器使用有效的url启动时,这段代码运行良好。

我的其余代码是

// Launches a browser based on the value specified in the properties file
public class LaunchBrowser {
public static WebDriver driver;
private String browser;
private String url;
private String iedriverpath;
// starts up a browser session and navigates to the url specified
@Test
public void startBrowser() throws Exception {
    switch (browser) {
        case "IE":  // Set IE driver path
            File ieFile = new File (iedriverpath);
            System.setProperty("webdriver.ie.driver", ieFile.getAbsolutePath());
            DesiredCapabilities dc = DesiredCapabilities.internetExplorer();
            dc.setCapability("nativeEvents", false);
            driver = new InternetExplorerDriver(dc);
            break;
        default:
            throw new IllegalArgumentException("Invalid Browser Specified!!!");
    }
    driver.get(url);
    driver.manage().window().maximize();        
    WebElement ele = driver.findElement(By.id("home_title"));
    }
}

我试图找到的元素的HTML看起来像这个

<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td width="33%" style="vertical-align:top;"></td>
<td width="33%" align="center">
<input id="home_title" class="home_title" type="text" readonly="true" title="Cloud Services"    value="Cloud Services" style="width: 142px;">
</td>
<td class="text-align-right" width="33%" nowrap="true" style="vertical-align:top;">
</tr>
</tbody>
</table>

你知道是什么导致了这个异常吗?是同步问题还是使用的定位器有问题?

非常感谢。

您需要切换框架。

driver.switchTo().frame("ID of frame");

那就做你的工作。。然后切换回来。

driver.switchTo().defaultContent();

最新更新