簡體   English   中英

IE11的org.openqa.selenium.NoSuchElementException

[英]org.openqa.selenium.NoSuchElementException for IE11

這里是硒的新手,請保持友好。

我在帶有Internet Explorer 11的Win 7上使用Selenium Webdriver 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM