|
我用下面的代码,在IE中定位元素,By.id, name, className, 都定位不到,为什么呀,我折腾了两天了,救命啊。。。。。。。我保存了一个页面的源码到附件中
public WebDriver getOWAPage(String owaURL,String browserType){
if(browserType.equalsIgnoreCase("FireFox")){
ProfilesIni profile = new ProfilesIni();
FirefoxProfile fp = profile.getProfile("default");
//fp.setPreference("intl.accept_languages", "en-US");
driver = new FirefoxDriver(fp);
}
if(browserType.equalsIgnoreCase("IE")){
System.setProperty("webdriver.ie.driver", "E:\\workspace\\SeleniumProject\\IEDriverServer.exe");
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
driver = new InternetExplorerDriver(ieCapabilities);
// WebDriver driver = new InternetExplorerDriver();
}
if(browserType.equalsIgnoreCase("Chrome")){
System.setProperty("webdriver.chrome.driver", "E:\\workspace\\SeleniumProject\\chromedriver2.10.exe");
driver = new ChromeDriver();
}
driver.get(owaURL);
return driver;
}
driver = loadOWAUtil.getOWAPage("file:///C:/test.html", "IE");
driver.manage().window().maximize();
Thread.sleep(10000);
System.out.println(driver.getTitle()+"--------title");
WebElement exceptionAddBtn = null;
try{
System.out.println(driver.getPageSource());
List<WebElement> tempList = driver.findElements(By.className("securityError"));
exceptionAddBtn = driver.findElement(By.id("linkdiv"));
System.out.println(exceptionAddBtn.getTagName());
exceptionAddBtn.click();
}catch(Exception e){
System.out.println("Exception Link in IE is not found");
e.printStackTrace();
}
|
|