我的 IE 浏览器之前设置了代理。我想在运行时初始化新的 InternetExplorerDriver 实例时设置直接连接(无代理)。我可以用 FirefoxProfile 做到这一点,但不能用 DesiredCapabilities。下面的代码只是设置了指定的代理,但没有设置代理。你能帮我为 InternetExplorerDriver 设置不代理吗?
String PROXY = "localhost:8080";
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setHttpProxy(PROXY)
.setFtpProxy(PROXY)
.setSslProxy(PROXY);
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new InternetExplorerDriver(cap);
我会有类似的东西:
Proxy proxy = Proxy.NO_Proxy;
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
WebDriver driver = new InternetExplorerDriver(cap);
[编辑]
String ieDriverPath = Constants.PROJECT_PATH + "\\src\\lib\\handler\\IEDriverServer.exe";
DesiredCapabilities ieCapabilities = new DesiredCapabilities();
org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();
proxy.setProxyType(org.openqa.selenium.Proxy.ProxyType.DIRECT);
ieCapabilities.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.ie.driver", ieDriverPath);
WebDriver webDriver = new InternetExplorerDriver(ieCapabilities);
webDriver.manage().timeouts().implicitlyWait(Constants.SE_WAIT_IN_SECOND, TimeUnit.SECONDS);
上面的代码不起作用。故障如下:
Aug 14, 2013 9:09:57 AM org.openqa.selenium.browserlaunchers.WindowsProxyManager backupRegistrySettings
INFO: Backing up registry settings...
Exception in thread "main" java.lang.RuntimeException: Bug extracting hudsuckr
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.extractHudsuckr(WindowsProxyManager.java:575)
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.runHudsuckr(WindowsProxyManager.java:585)
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.backupHudsuckrSettings(WindowsProxyManager.java:624)
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.backupRegistrySettings(WindowsProxyManager.java:286)
at org.openqa.selenium.ie.InternetExplorerDriver.prepareProxy(InternetExplorerDriver.java:296)
at org.openqa.selenium.ie.InternetExplorerDriver.run(InternetExplorerDriver.java:180)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:174)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:147)
at acccm.Testing.TID02.main(TID02.java:52)
Caused by: java.io.IOException: Unable to locate: hudsuckr/hudsuckr.exe
at org.openqa.selenium.io.FileHandler.locateResource(FileHandler.java:86)
at org.openqa.selenium.io.FileHandler.copyResource(FileHandler.java:55)
at org.openqa.selenium.browserlaunchers.WindowsProxyManager.extractHudsuckr(WindowsProxyManager.java:572)
... 8 more
Selenium version: 2.33
OS: Win 7 64 bit
Browser: IE
Browser version: 8,9
我会很感激你的帮助。
提前致谢。