我无法通过selenium脚本关闭Internet Explorer,我尝试了每个解决方案来杀死IEDriver任务和Iexplorer.exe。
我也尝试过解决方案:在Selenium Test 2 之后Internet Explorer 11没有关闭,但它仍然无法正常工作。 我在下面使用, 硒3.4, IE:11.1358.14393.0, InternetExplorerServerDriver:3.4.0
以下是我的代码。
import java.io.IOException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Tc03_IEDriver_First_use {
public static void main(String[] args) throws Exception {
//Set IEDriver Properties
System.setProperty("webdriver.ie.driver", "D:\\Rohit Bhatkar\\Selenium Jars\\IEDriverServer_x64_3.4.0\\IEDriverServer.exe");
//Set desired Capabilities of IE. these statements removes an zoomsetting error.
//You Can set Zoom mannually as, Go To View Menu on IE > Click On Zoom > Select 100%
DesiredCapabilities caps = DesiredCapabilities.internetExplorer();
caps.setCapability("ignoreZoomSetting", true);
//Create IEDriver obj, Open Browser, Open URL, Close the Browser
WebDriver obj1= new InternetExplorerDriver(caps);
obj1.manage().window().maximize();
obj1.get("https://www.google.com");
obj1.quit(); //IE not Closing. Steel need to do some work to close the browser
}
}
答案 0 :(得分:2)
我会先尝试obj1.close()
关闭浏览器窗口。然后,我将使用obj1.quit()
退出Webdriver,这将关闭Windows中的终端窗口。
答案 1 :(得分:1)
您的代码似乎运行正常。我测试了它,IE浏览器在最后关闭了。
尝试使用obj1.close();
代替obj1.quit();
答案 2 :(得分:1)
以下是您的问题的答案:
尝试IE 11的这些设置:
Note
:您必须将Zoom Level
设置为 100%才能使IE正常运行。
System.setProperty("webdriver.ie.driver", "C:\\Utility\\BrowserDrivers\\IEDriverServer.exe");
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("platform", "WIN8");
cap.setCapability("version", "11");
cap.setCapability("browserName", "internet explorer");
cap.setCapability("ignoreProtectedModeSettings",1);
cap.setCapability("nativeEvents","false");
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability("requireWindowFocus","true");
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
WebDriver driver = new InternetExplorerDriver(cap);
driver.manage().window().maximize();
driver.get("https://google.co.in");
System.out.println(driver.getTitle());
driver.quit();
如果这回答你的问题,请告诉我。