Để khởi tạo IE trong Webdriver thì phức tạp hơn trong FF hay Chrome. Bài viết này sẽ nêu rõ từng bước để khởi tạo IE.
Bước 1: Khởi động IE và cấu hình như sau: Vào Tools -> Internet Options -> Security -> Đánh dấu ‘Enable Protected Mode’ như hình bên dưới
Bước 2: SetProperties cho IE sử dụng phương thức System.setProperty()
Bưới 3: Khởi tạo DesiredCapabilities và đặt InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS về giá trị ‘true’
Bước 4: Khởi tạo Webdriver
Bên dưới là đoạn Java code đầy đủ mở 1 trang web bằng IE
package training;package training; import org.openqa.selenium.WebDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.openqa.selenium.remote.DesiredCapabilities; public class LauchIE { public static void main(String[] args) { System.setProperty("webdriver.ie.driver", "../SeleniumWebDriverPractice.Training/libs/IEDriverServer64.exe"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); WebDriver driver = new InternetExplorerDriver(capabilities); driver.get("http://thichblog.net"); } }
Leave a Reply