Open Jacobvu84 opened 5 years ago
Đối với trình duyệt Firefox để thay đổi cấu hình của Gecko Driver
public FirefoxDriver getDriver() {
// 1 profile
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.homepage", "http://www.google.com");
//profile.setPreference("browser.privatebrowsing.autostart", true);
// 2 capaibilities
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.IGNORE);
// 3. options
FirefoxOptions options = new FirefoxOptions(capabilities);
// options.addArguments("--headless");
// options.addArguments("--width=800");
// options.addArguments("--height=800");
options.addArguments("-private");
// 4. Initialization (constructor ) firefox webdriver
eturn new FirefoxDriver(options);
}
Hiện tại, trên Selenium javadocs trong mục
org.openqa.selenium.chrome.ChromeDriver
ta thấy việc sử dụngDesiredCapabilities
thay đổi cấu hình ChromeDriver đã bị đánh dấu@Deprecated
nghĩa là KHÔNG CÒN DÙNG nữa mà thay vào đó là sẽ sử dụngChromeOptions
. Tham khảo thêm tại Capabilities & ChromeOptionsĐồng thời cũng có rất nhiều sự thay đổi trong bản thân các trình duyệt. Ví dụ: Trước đây việc xử lý popup boxs như là Alert, Confirm hay Prompt mặc định là
ingore
thì giờ đây nó để mặc định làdismiss and notify
nên để handle được các popup này cần phải thay đổi lại giá trịCapabilityType.UNEXPECTED_ALERT_BEHAVIOUR
là ignore nếu không cứ có popup hiện lên nó sẽ auto là chọn vào dismiss và đẩy ra thông báo exception làNoAlertPresent
....Mình xin được update thông tin và chia sẻ cho các bạn source code mẫu để khởi tạo ChromeDriver theo cách mới.
Đừng quên theo dõi mình trên fan page hoặc trên youtube channel . Mình sẽ update nhưng thay đổi mới nhất nếu có cho mọi người.