I'm upgrading from Selenium 2.53 to 4.3.0. I have a block of code that is not working now with the newer Selenium version. It worked fine with the older 2.53 version.
public static DesiredCapabilities getChromeCapabilities() {
log.debug("Configuring LOG");
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable(LogType.BROWSER, Level.ALL);
log.debug("Configuring Chrome");
//This line gives a message saying "Cannot resolve method 'chrome()'
DesiredCapabilities desiredCaps = DesiredCapabilities.chrome
desiredCaps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
ChromeOptions options = new ChromeOptions;
//This line gives a message saying "Cannot resolve method 'addArguments(java.lang.String)'
options.addArguments("--no-sandbox");
//This line gives a message saying "Cannot resolve method 'addArguments(java.lang.String)'
options.addArguments("disable-infobars");
//This line gives a message saying "Cannot resolve method 'addArguments(java.lang.String)'
options.addArguments("--ignore-certificate-errors");
//This line gives a message saying "Cannot resolve method 'addArguments(java.lang.String)'
options.addArguments("--window-position=0,0");
//This line gives a message saying "Cannot resolve method 'addArguments(java.lang.String)'
options.addArguments("--window-size=1920,1080");
//This line gives a message saying "Cannot resolve method 'setExperimentationalOption(java.lang.String, java.util.List<T>)'
options.setExperimentationalOption("excludeSwitches, Arrays.asList("enable-automation",
"disable-impl-side-painting"));
Map<String,Object> prefs = new HashMap<~>();
prefs.put("credentials_enable_service",false);
prefs.put("profile.password_manager_enabled",false);
prefs.put("plugins.always_open_pdf_externally",true);
//This line gives a message saying "Cannot resolve method 'setExperimentationalOption(java.lang.String, java.util.Map<java.lang.String,java.lang.Object>)'
options.setExperimentationalOption("prefs",prefs);
desiredCaps.setCapability(ChromeOptions.CAPABILITY, options);
return desiredCaps;
}
I'm not sure what to replace this with:
DesiredCapabilities desiredCaps = DesiredCapabilities.chrome
I'm also not sure why addArgument() and setExperimentationalOption() are not resolving. I think they're being used in the correct way here, so I'm not sure what the problem is. I have the following import statement at the top:
import org.openqa.selenium.chrome.ChromeOptions;