Best Selenium code snippet using org.openqa.selenium.Proxy.setSslProxy
Source:BrowserHelper.java
...63 capabilities.setCapability(CapabilityType.LOGGING_PREFS, loggingPreferences);64 Proxy proxy = new Proxy();65 proxy.setHttpProxy(proxyConnectionString)66 .setFtpProxy(proxyConnectionString)67 .setSslProxy(proxyConnectionString)68 .setSocksProxy(proxyConnectionString);69 capabilities.setCapability(CapabilityType.PROXY, proxy);70 WebDriver driver = new ChromeDriver(capabilities);71 setupBrowser(driver);72 return driver;73 }74 public static RemoteTestNode getRemoteChrome(String proxyConnectionString, RemoteTestNodeURL remoteTestNodeURL) {75 try {76 DesiredCapabilities capabilities = DesiredCapabilities.chrome();77 ChromeOptions options = new ChromeOptions();78 options.addArguments("test-type");79 capabilities.setCapability(ChromeOptions.CAPABILITY, options);80 Proxy proxy = new Proxy();81 proxy.setHttpProxy(proxyConnectionString)82 .setFtpProxy(proxyConnectionString)83 .setSslProxy(proxyConnectionString);84 capabilities.setCapability(CapabilityType.PROXY, proxy);85 WebDriver driver = new RemoteWebDriver(new URL(remoteTestNodeURL.getRegistrationURL()), capabilities);86 setupBrowser(driver);87 RemoteTestNode remoteTestNode = new RemoteTestNode()88 .setRemoteTestNodeURL(remoteTestNodeURL)89 .setWebDriver(driver);90 BrowserManager.getInstance().addBrowser(driver);91 return remoteTestNode;92 } catch (MalformedURLException e) {93 e.printStackTrace();94 }95 return null;96 }97 public static WebDriver getFireFox(String proxyConnectionString) {98 DesiredCapabilities capabilities = DesiredCapabilities.firefox();99 Proxy proxy = new Proxy();100 proxy.setHttpProxy(proxyConnectionString)101 .setFtpProxy(proxyConnectionString)102 .setSslProxy(proxyConnectionString);103 capabilities.setCapability(CapabilityType.PROXY, proxy);104 WebDriver driver = new FirefoxDriver(capabilities);105 setupBrowser(driver);106 return driver;107 }108 public static WebDriver getOpera(String proxyConnectionString) {109 DesiredCapabilities capabilities = DesiredCapabilities.operaBlink();110 if (SDEUtils.isJar()) {111 try {112 URI uri = SDEUtils.getFile(SDEUtils.getJarURI(), "WebDrivers/" + OPREA_DRIVER);113 System.setProperty("webdriver.opera.driver", uri.getPath());114 } catch (IOException | URISyntaxException e) {115 e.printStackTrace();116 }117 } else {118 System.setProperty("webdriver.opera.driver", SDEUtils.getResourcePath() + "/WebDrivers/" + OPREA_DRIVER);119 }120 OperaOptions options = new OperaOptions();121 options.addArguments("ignore-certificate-errors");122 capabilities.setCapability(OperaOptions.CAPABILITY, options);123 Proxy proxy = new Proxy();124 proxy.setHttpProxy(proxyConnectionString)125 .setFtpProxy(proxyConnectionString)126 .setSslProxy(proxyConnectionString);127 capabilities.setCapability(CapabilityType.PROXY, proxy);128 WebDriver driver = new OperaDriver(capabilities);129 setupBrowser(driver);130 return driver;131 }132 public static WebDriver getIE(String proxyConnectionString) {133 DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();134 if (SDEUtils.isJar()) {135 try {136 URI uri = SDEUtils.getFile(SDEUtils.getJarURI(), "WebDrivers/" + IE_DRIVER);137 System.setProperty("webdriver.ie.driver", uri.getPath());138 } catch (IOException | URISyntaxException e) {139 e.printStackTrace();140 }141 } else {142 System.setProperty("webdriver.ie.driver", SDEUtils.getResourcePath() + "/WebDrivers/" + IE_DRIVER);143 }144 Proxy proxy = new Proxy();145 proxy.setHttpProxy(proxyConnectionString)146 .setFtpProxy(proxyConnectionString)147 .setSslProxy(proxyConnectionString);148 capabilities.setCapability(CapabilityType.PROXY, proxy);149 capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);150 WebDriver driver = new InternetExplorerDriver(capabilities);151 setupBrowser(driver);152 return driver;153 }154 private static void setupBrowser(WebDriver driver) {155 Double screenHeight = Toolkit.getDefaultToolkit().getScreenSize().getHeight();156 Double screenWidth = Toolkit.getDefaultToolkit().getScreenSize().getWidth();157 driver.manage().window().setSize(new Dimension(screenWidth.intValue(), screenHeight.intValue()));158 driver.manage().window().setPosition(new Point(0, 0));159 BrowserManager.getInstance().addBrowser(driver);160 driver.manage().deleteAllCookies();161 }...
Source:SeleniumBrowser.java
...45 if (proxyIP.compareTo("") !=0) {46 ChromeOptions options = new ChromeOptions();47 org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();48 proxy.setHttpProxy(proxyIP + ":8080");49 proxy.setSslProxy(proxyIP + ":8443");50 proxy.setNoProxy("localhost; 127.0.0.1; <local>;*.pingidentity.com;login.trustwave.com;*.pingone.com");51 options.setCapability("proxy", proxy);52 if(loadProxyExtension) {53 //location of "Proxy Auto Auth" extension which inserts proxy user name and password automatically54 //https://chrome.google.com/webstore/detail/proxy-auto-auth/ggmdpepbjljkkkdaklfihhngmmgmpggp?hl=en55 String proxyAutoAuth = "C:\\Selenium\\Utils\\extension_2_0.crx";56 File extension = new File(proxyAutoAuth);57 if(!extension.exists())58 org.testng.Assert.fail("Could not find Proxy Auto Extension. Please copy it to the following location: " + proxyAutoAuth);59 options.addExtensions(extension);60 }61 driver = new ChromeDriver(options);62 }63 else {64 HashMap<String, Object> chromePrefs = new HashMap<String, Object>();65 chromePrefs.put("safebrowsing.enabled", "false");66 //chromePrefs.put("profile.default_content_settings.popups", 0);67 //chromePrefs.put("download.prompt_for_download", "false");68 String downloadFilepath = PropertiesFile.readProperty("DownloadFolder");69 chromePrefs.put("download.default_directory", downloadFilepath);70 ChromeOptions options = new ChromeOptions();71 options.setExperimentalOption("prefs", chromePrefs);72 driver = new ChromeDriver(options);73 }74 75 break;76 case "Firefox":77 System.setProperty("webdriver.gecko.driver", "C:\\Selenium\\geckodriver.exe");78 if (proxyIP.compareTo("") !=0) {79 FirefoxProfile profile = new FirefoxProfile();80 FirefoxOptions options = new FirefoxOptions();81 profile.setPreference("network.proxy.type", 1);82 profile.setPreference("network.proxy.http", proxyIP);83 profile.setPreference("network.proxy.http_port", 8080);84 profile.setPreference("network.proxy.ssl", proxyIP);85 profile.setPreference("network.proxy.ssl_port", 8443);86 profile.setPreference("network.proxy.no_proxies_on", "localhost, 127.0.0.1, <local>,*.pingidentity.com,login.trustwave.com,*.pingone.com");87 // options.setHeadless(true);88 options.setProfile(profile);89 options.addPreference("security.sandbox.content.level", 5);90 driver = new FirefoxDriver(options);91 //driver.manage().deleteAllCookies();92 }93 else {94 driver = new FirefoxDriver();95 }96 break;97 98 case "IE" :99 File file = new File("C:/Selenium/IEDriverServer.exe");100 System.setProperty("webdriver.ie.driver", file.getAbsolutePath());101 if (proxyIP.compareTo("")!=0) {102 org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();103 proxy.setHttpProxy(proxyIP + ":8080");104 proxy.setSslProxy(proxyIP + ":8443");105 // proxy.setNoProxy("localhost, 127.0.0.1, *.pingone.com,106 // *.pingidentity.com, shib19.finjan.com, login.trustwave.com,107 // inc.tw-test.net, inb.tw-test.net, ina.tw-test.net,108 // login.windows.net, login.microsoftonline.com,109 // secure.aadcdn.microsoftonline-p.com, *.oktapreview.com,110 // *.oktacdn.com");111 }112 //InternetExplorerOptions options = new InternetExplorerOptions();113 break;114 115 default:116 driver = null;117 break;118 }...
Source:Browser.java
...36 String PROXY = proxy.getIp()+":"+proxy.getPort();37 org.openqa.selenium.Proxy seleniumProxy = new org.openqa.selenium.Proxy();38 seleniumProxy.setHttpProxy(PROXY)39 .setFtpProxy(PROXY)40 .setSslProxy(PROXY);41 DesiredCapabilities cap = new DesiredCapabilities();42 cap.setCapability(CapabilityType.PROXY, proxy);43 return new FirefoxDriver(cap);44 }45 return new FirefoxDriver();46 }47 },48 IE {49 @Override50 public WebDriver init(String path, Proxy proxy) {51 System.setProperty("webdriver.ie.driver", path);52 if (proxy!=null) {53 String PROXY = proxy.getIp()+":"+proxy.getPort();54 org.openqa.selenium.Proxy seleniumProxy = new org.openqa.selenium.Proxy();55 seleniumProxy.setHttpProxy(PROXY)56 .setFtpProxy(PROXY)57 .setSslProxy(PROXY);58 DesiredCapabilities cap = new DesiredCapabilities();59 cap.setCapability(CapabilityType.PROXY, proxy);60 return new InternetExplorerDriver(cap);61 }62 return new InternetExplorerDriver();63 }64 },65 PHANTOMJS {66 @Override67 public WebDriver init(String path, Proxy proxy) {68 DesiredCapabilities capabilities = new DesiredCapabilities();69 capabilities.setCapability("phantomjs.binary.path", path);70 capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);71 capabilities.setJavascriptEnabled(true);...
Source:SeleniumGeter.java
...18 Proxy proxy = new Proxy();19 proxy.setHttpProxy(PROXY)20 .setFtpProxy(PROXY)21 .setSocksProxy(PROXY)22 .setSslProxy(PROXY);23 proxy.setProxyType(Proxy.ProxyType.MANUAL);24 capabilities.setCapability(CapabilityType.PROXY, proxy);25// capabilities.setJavascriptEnabled(true);26 WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:8910"), DesiredCapabilities.phantomjs());27// WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), capabilities);28 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);29 driver.get("http://www.baidu.com/#ie=UTF-8&wd=ip");30 Thread.sleep(2000);31 String str = driver.getPageSource();32 driver.close();33 System.out.println(str);34 }35 @Override36 public String getHtml(String url) {37 try {38 DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();39// String PROXY = "127.0.0.1:1080";40// Proxy proxy = new Proxy();41// proxy.setHttpProxy(PROXY)42// .setFtpProxy(PROXY)43// .setSocksProxy(PROXY)44// .setSslProxy(PROXY);45// proxy.setProxyType(Proxy.ProxyType.MANUAL);46// capabilities.setCapability(CapabilityType.PROXY, proxy);47// WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:4444/wd/hub"), DesiredCapabilities.phantomjs());48// WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:8910"), DesiredCapabilities.phantomjs());49 WebDriver driver = new RemoteWebDriver(new URL("http://127.0.0.1:8910"), capabilities);50 driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);51 driver.get(url);52 Thread.sleep(2000);53 String str = driver.getPageSource();54 driver.close();55 return str;56 } catch (Exception e) {57 return "";58 }...
Source:BasicTest.java
...16 System.setProperty("webdriver.chrome.driver", new File("chromedriver_linux").getAbsolutePath());17 org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();18 proxy.setHttpProxy(PROXY)19 .setFtpProxy(PROXY)20 .setSslProxy(PROXY);21 DesiredCapabilities capabilities = new DesiredCapabilities();22 capabilities.setCapability(CapabilityType.PROXY, proxy);23 //capabilities.setCapability("marionette", true);24 capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");25 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);26 driver.get("http://newtours.demoaut.com/");27 driver.quit();28 //SimpleZAPExample.main(null);29 }30 @Test(enabled=false)31 public void firefoxTest() throws MalformedURLException {32 // TODO Auto-generated method stub33 String PROXY = "localhost:8090";34 System.setProperty("webdriver.gecko.driver", new File("geckodriver_mac").getAbsolutePath());35 org.openqa.selenium.Proxy proxy = new org.openqa.selenium.Proxy();36 proxy.setHttpProxy(PROXY)37 .setFtpProxy(PROXY)38 .setSslProxy(PROXY);39 DesiredCapabilities capabilities = new DesiredCapabilities();40 capabilities.setCapability(CapabilityType.PROXY, proxy);41 capabilities.setCapability("marionette", true);42 capabilities.setCapability(CapabilityType.BROWSER_NAME, "firefox");43 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);44 driver.get("http://newtours.demoaut.com/");45 driver.quit();46 //SimpleZAPExample.main(null);47 }48}...
Source:Test.java
...31 32 Proxy pxy = new Proxy();33 pxy.setHttpProxy("")34 .setFtpProxy("")35 .setSslProxy("");36 DesiredCapabilities dsg = new DesiredCapabilities();37 dsg.setCapability(CapabilityType.PROXY, pxy);38 39 40 //Driver wait41 WebDriverWait wait = new WebDriverWait(driver, 10);42 //WebElement ele = wait.until(ExpectedConditions.elementToBeClickable(by));43 44 45 }46 47}...
Source:ffopt.java
...13 //WebDriver driver=new FirefoxDriver();14Proxy proxy = new Proxy();15//Adding the desired host and port for the http, ssl, and ftp Proxy Servers respectively16proxy.setHttpProxy("127.0.0.1:5000");17proxy.setSslProxy("127.0.0.1:5001");18//proxy.setSslProxy("127.0.0.1:5002");19//proxy.setFtpProxy("127.0.0.1:5003");20FirefoxOptions options = new FirefoxOptions();21options.setCapability("proxy", proxy);22//Calling new Firefox profile for test23WebDriver driver = new FirefoxDriver(options);24driver.get("https://www.browserstack.com/");25driver.manage().window().maximize();26//driver.quit();27}
...
Source:TestPointAttack.java
...14 System.setProperty("webdriver.chrome.driver", "C:\\SELENIUM\\Chrome\\chromedriver.exe");15 Proxy proxy = new Proxy();16 proxy.setHttpProxy("localhost:8090");17 proxy.setFtpProxy("localhost:8090");18 proxy.setSslProxy("localhost:8090");19 DesiredCapabilities capabilities = new DesiredCapabilities();20 capabilities.setCapability(CapabilityType.PROXY, proxy);21 driver1 = new ChromeDriver(capabilities);22 driver1.get("https://www.testpoint.com.au/");23 driver1.findElement(By.xpath("//a[@href='https://www.testpoint.com.au/contact-us/']")).click();24 driver1.close();25 }26}...
setSslProxy
Using AI Code Generation
1import org.openqa.selenium.Proxy;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.chrome.ChromeOptions;5public class SetSslProxy {6 public static void main(String[] args) {7 System.setProperty("webdriver.chrome.driver", "chromedriver.exe");8 Proxy proxy = new Proxy();9 proxy.setSslProxy("localhost:8080");10 ChromeOptions options = new ChromeOptions();11 options.setProxy(proxy);12 WebDriver driver = new ChromeDriver(options);13 driver.quit();14 }15}
setSslProxy
Using AI Code Generation
1import org.openqa.selenium.Proxy2import org.openqa.selenium.WebDriver3import org.openqa.selenium.chrome.ChromeDriver4import org.openqa.selenium.chrome.ChromeOptions5import org.openqa.selenium.remote.CapabilityType6import org.openqa.selenium.remote.DesiredCapabilities7def proxy = new Proxy()8proxy.setSslProxy("
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!