Reputation: 51
Context: Getting error as method chrome undefined from the below code:
package zapSeleniumIntegration;
import java.lang.reflect.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class BrowserDriverFactory {
static WebDriver driver;
public static WebDriver createChromeDriver(Proxy proxy, String path) {
// Set proxy in the chrome browser
DesiredCapabilities capabilities = DesiredCapabilities.chrome();//Getting error as method chrome undefined
capabilities.setCapability("127.0.0.1", 8080);
// Set system property for chrome driver with the path
System.setProperty("webdriver.chrome.driver", "C:\\Users\\kotla.naveen\\Desktop\\chromedriver.exe");
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);
return new ChromeDriver(options);
}
}
Upvotes: 5
Views: 14152
Reputation: 1
Use the following line instead : DesiredCapabilities capabilities = new DesiredCapabilities();
Upvotes: 0
Reputation: 1417
The old method Capabilities is deprecated. Use ChromeOptions object and passed it to the
ChromeDriver()
constructor. Also, you don't need to useoptions.merge(capabilities);
instead, you can useoptions.setCapability(params, params)
However, You can completely skip DesiredCapabilities and use only ChromeOptions with setCapability method as mentioned below:
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
options.setAcceptInsecureCerts(true);
options.setUnhandledPromptBehaviour(UnexpectedAlertBehaviour.ACCEPT);
//Set the pre defined capability – ACCEPT_SSL_CERTS value to true:
options.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
//Pass the chromeoption object to the ChromeDriver:
WebDriver driver = new ChromeDriver(options);
************** To set proxy **************
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setAutodetect(false);
proxy.setHttpProxy("proxy_url:port");
proxy.setSslProxy("proxy_url:port");
proxy.setNoProxy("no_proxy-var");
options.setCapability("proxy", proxy);
driver = new ChromeDriver(options);
Upvotes: 4