2014-10-27 46 views
0

这里新来的硒,请你好。org.openqa.selenium.NoSuchElementException for IE11

我在使用Internet Explorer 11的win 7上使用selenium webdriver 2.41.0并获取以下“org.openqa.selenium.NoSuchElementException:无法找到ID为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> 

任何想法可能会导致异常的元素?它是同步问题还是使用定位器的问题?

感谢堆。

+0

是什么结构看起来像表上方?其他司机是否工作? – bcar 2014-10-27 03:14:12

+0

我用firefox 30.0试过并得到同样的问题 – r0b0t99 2014-10-27 03:39:12

+0

有没有办法附加一个文件?我可以附加/上传完整的HTML文件,如果它的任何帮助... – r0b0t99 2014-10-27 03:40:24

回答

0

您需要切换帧。

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

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

driver.switchTo().defaultContent(); 
+0

谢谢先生,那曾经工作过:) :) – r0b0t99 2014-10-27 03:57:45

+0

没问题。乐意效劳!祝你的代码好运! – bcar 2014-10-27 03:58:34