让自己的Selenium程序成功的自动打开网页-问题记录

发表于:2016-6-27 11:39

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:流浪骑士    来源:51Testing软件测试网采编

  第一次执行:
package mycss;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Test1 {
public static void main(String[] args) {
WebDriver driver = new InternetExplorerDriver();
driver.get("www.baidu.com");
}
}
  报错如图:
  Paste_Image.png
  下载IEDriverServer.exe并放在代码工程路径下面,然后修改代码继续运行:
package mycss;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Test1 {
public static void main(String[] args) {
String IEPath = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
String pro_Path = System.getProperty("user.dir");
String IEDriver_Path = pro_Path + "\\IEDriverServer.exe";
System.setProperty("webdriver.ie.bin", IEPath);
System.setProperty("webdriver.ie.driver", IEDriver_Path);
WebDriver driver = new InternetExplorerDriver();
driver.get("www.baidu.com");
}
}
  运行后又报错:
  
  再次修改:
package mycss;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Test1 {
public static void main(String[] args) {
//ie浏览器路径
String IEPath = "C:\\Program Files\\Internet Explorer\\iexplore.exe";
String pro_Path = System.getProperty("user.dir");
//打开ie浏览器的driver
String IEDriver_Path = pro_Path + "\\IEDriverServer.exe";
System.setProperty("webdriver.ie.bin", IEPath);
System.setProperty("webdriver.ie.driver", IEDriver_Path);
//设置IE安全机制
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(ieCapabilities);
driver.get("www.baidu.com");
}
}
  这次终于打开IE浏览器了。
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号