{"id":20710006,"url":"https://github.com/oxylabs/selenium-proxy-integration-java","last_synced_at":"2025-04-23T04:48:22.094Z","repository":{"id":46148446,"uuid":"424921415","full_name":"oxylabs/selenium-proxy-integration-java","owner":"oxylabs","description":"Oxylabsʼ Residential Proxies integration with Selenium using Java","archived":false,"fork":false,"pushed_at":"2025-02-11T12:43:24.000Z","size":617,"stargazers_count":6,"open_issues_count":0,"forks_count":3,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-29T22:12:06.414Z","etag":null,"topics":["java","java-proxy","proxy-list","proxy-list-github","proxy-site","rotating-proxy","selenium","socks5-proxy","socks5-proxy-list","socks5-server","socks5-server-java","web-proxy"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxylabs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-11-05T11:16:22.000Z","updated_at":"2025-02-11T12:43:27.000Z","dependencies_parsed_at":"2024-04-19T12:24:24.750Z","dependency_job_id":"46f8f944-0392-43fb-9000-6ba593fd46e2","html_url":"https://github.com/oxylabs/selenium-proxy-integration-java","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fselenium-proxy-integration-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fselenium-proxy-integration-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fselenium-proxy-integration-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxylabs%2Fselenium-proxy-integration-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxylabs","download_url":"https://codeload.github.com/oxylabs/selenium-proxy-integration-java/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250372939,"owners_count":21419722,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java-proxy","proxy-list","proxy-list-github","proxy-site","rotating-proxy","selenium","socks5-proxy","socks5-proxy-list","socks5-server","socks5-server-java","web-proxy"],"created_at":"2024-11-17T02:09:32.329Z","updated_at":"2025-04-23T04:48:22.087Z","avatar_url":"https://github.com/oxylabs.png","language":"Java","readme":"# Oxylabs’ Residential Proxies integration with Selenium using Java\n\n[![Oxylabs promo code](https://raw.githubusercontent.com/oxylabs/product-integrations/refs/heads/master/Affiliate-Universal-1090x275.png)](https://oxylabs.go2cloud.org/aff_c?offer_id=7\u0026aff_id=877\u0026url_id=112)\n\n[![](https://dcbadge.vercel.app/api/server/eWsVUJrnG5)](https://discord.gg/GbxmdGhZjq)\n\n[\u003cimg src=\"https://img.shields.io/static/v1?label=\u0026message=Java\u0026color=brightgreen\" /\u003e](https://github.com/topics/java) [\u003cimg src=\"https://img.shields.io/static/v1?label=\u0026message=Selenium\u0026color=orange\" /\u003e](https://github.com/topics/selenium) [\u003cimg src=\"https://img.shields.io/static/v1?label=\u0026message=Web-Scraping\u0026color=yellow\" /\u003e](https://github.com/topics/web-scraping) [\u003cimg src=\"https://img.shields.io/static/v1?label=\u0026message=Rotating%20Proxies\u0026color=blueviolet\" /\u003e](https://github.com/topics/rotating-proxies)\n\n- [Introduction](#introduction)\n- [Prerequisites](#prerequisites)\n- [Requirements](#requirements)\n- [Running the Code](#running-the-code)\n  - [Compiling the Source Code](#compiling-the-source-code)\n  - [Running the Jar](#running-the-jar)\n- [Proxy Authentication](#proxy-authentication)\n- [Testing Proxy Connection](#testing-proxy-connection)\n- [Getting Country Specific Proxy](#getting-country-specific-proxy)\n- [SSL Support](#ssl-support)\n  - [Installation Certificate for macOS](#installation-certificate-for-macos)\n  - [Installation Certificate for Windows](#installation-certificate-for-windows)\n- [Understanding the Code](#understanding-the-code)\n\n## Introduction\n\nIntegrating proxies that need authorization using the Selenium framework and Java programming \nlanguage can be challenging. \n\nThis tutorial contains complete code demonstrating how [Oxylabs’ Residential Proxies](https://oxy.yt/RrBU) can be \neasily integrated with Selenium using Java. \n\n## Prerequisites\n\n- Download and install [Maven](https://maven.apache.org/download.cgi).\n- Download and install [Java SE Development Kit](https://www.oracle.com/java/technologies/downloads/).\n- Download and install [Google Chrome](https://www.google.com/chrome).\n\n## Requirements\n\nTo make this integration easier, we used [BrowserMob Proxy](https://github.com/lightbody/browsermob-proxy) \nas a middle layer. It runs proxies locally in JVM and allows chaining of Oxylabs' authenticated proxies. \nIf you’re using Maven, add this dependency to the `pom.xml` file:\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003enet.lightbody.bmp\u003c/groupId\u003e\n    \u003cartifactId\u003ebrowsermob-core\u003c/artifactId\u003e\n    \u003cversion\u003e2.1.5\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nThe other library used in this project – [WebDriverManager](https://github.com/bonigarcia/webdrivermanager), \nis optional. It just makes downloading and setting up [Chrome Driver](https://chromedriver.chromium.org/downloads) \neasier. To use this library, include the following dependency in `pom.xml` file:\n\n```xml\n\n\u003cdependency\u003e\n    \u003cgroupId\u003eio.github.bonigarcia\u003c/groupId\u003e\n    \u003cartifactId\u003ewebdrivermanager\u003c/artifactId\u003e\n    \u003cversion\u003e5.0.2\u003c/version\u003e\n\u003c/dependency\u003e\n```\n\nIf you don’t want to use WebDriverManager, download the Chrome Driver and set the system property as follows:\n\n```java\nSystem.setProperty(\"webdriver.chrome.driver\",\"/path/to/chromedriver\");\n```\n\n## Running the Code\n\n### Compiling the Source Code\n\nThis is a maven project. To compile this project, run the following command from terminal:\n\n```shell\nmvn clean package\n```\n\nThis will create the file `oxylabs.io-jar-with-dependencies.jar` in the `target` folder.\n\n### Running the Jar\n\nTo run the jar, execute the following command from the terminal:\n\n```shell\njava -cp target/oxylabs.io-jar-with-dependencies.jar ProxyDemo\n```\n\n## Proxy Authentication\n\nOpen [ProxySetup.java](src/main/java/ProxySetup.java) file and update your username, password, and endpoint.\n\n```java\nstatic final String ENDPOINT=\"pr.oxylabs.io:7777\";\nstatic final String USERNAME=\"yourUsername\";\nstatic final String PASSWORD=\"yourPassword\";\n```\n\nYou shouldn’t include the prefix `customer-` in the `USERNAME.` This will be added in the code for country-specific proxies.\n\n## Testing Proxy Connection\n\nOpen this project in IDE, open the [ProxySetup.java](src/main/java/ProxySetup.java) file, and run the `main()` function. \nThis will print two IP addresses.\n\n- The first IP address will be completely random;\n- The second IP address will be a country-specific IP address in Germany.\n\n## Getting Country Specific Proxy\n\nOpen [ProxyDemo.java](src/main/java/ProxyDemo.java) file and send a two-letter country code to the function `CountrySpecficIPDemo`.\n\n```java\ncountrySpecificIPDemo(\"DE\");\n```\n\nThe value of this parameter is a case-insensitive country code in two-letter [3166-1 alpha-2 format](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). For example, `DE` for \nGermany, `GB` for the United Kingdom, etc. For more details, see Oxylabs’ [documentation](https://developers.oxylabs.io/proxies/residential-proxies/select-country#code-example).\n\n## SSL Support\n\nThis code uses BrowserMob Proxy, which supports full MITM. \n\nYou may still see invalid certificates warnings. To solve this, install the [ca-certificate-rsa.cer](certificates/ca-certificate-rsa.cer) file in your browser or HTTP client. Alternatively you can generate your own private key rather than using the .cer files distributed with repository.\n\n### Installation Certificate for macOS\n- Open Keychain Access\n- Selct `System` on left bar\n- Click the padlock icon next to `System` and enter your password when prompted\n- Select `Certificates` tab on the top\n- Drag and drop the `ca-certificate-rsa.cer` file into the `Certificates` tab. You will notice a new certificate appears in the `Certificates` tab with the name `LittleProxy MITM`.\n\n![](images/Keychain.png)\n- Right click the certificate and select `Get Info`\n- Select `Always Trust`, close the dialog, and enter password again when promoted\n  \n![](images/mcos_trust.png)\n\n\n\n### Installation Certificate for Windows\n\n- Open the `ca-certificate-rsa.cer` file in Windows Explorer.\n- Right click the file, and select `Install`.\n- In the Certificate Import Wizard window, click `Browse` and select `Trusted Publishers`. Click `OK` to continue.\n\n![](images/Windows_Step1.png)\n- If you see a Security Warning, select `Yes`.\n\n![](images/Windows_Step2.png)\n- Follow the wizard to complete the installation.\n\n## Understanding the Code\n\nAll the complexity of setting up BrowserMob Proxy and Chrome Options is hidden in\nthe [ProxyHelper](src/main/java/ProxyHelper.java) class.\n\nIn most cases, you should be able to use this file directly without any change.\n\nTo create a Chrome Driver instance, go through a two-step process as follows:\n\nFirst, create an instance of `BrowserMobProxyServer`. This is where you need to provide the proxy endpoint, username, and password.\n\nThe fourth parameter is a two-letter country code. If you don’t need a country-specific proxy, set it to `null`:\n\n```java\nBrowserMobProxyServer proxy=ProxyHelper.getProxy(\n        ProxySetup.ENDPOINT,\n        ProxySetup.USERNAME,\n        ProxySetup.PASSWORD,\n        countryCode)\n```\n\nNext, call the `ProxyHelper.getDriver()` function.\n\nThis function takes up two parameters -`BrowserMobProxyServer` and a `boolean` headless. To run the browser in headless mode, send `true`:\n\n```java\nWebDriver driver=ProxyHelper.getDriver(proxy,true);\n```\n\n`driver` is an instance of Chrome Driver.\n\nNow, you should write your code to use the Chrome Driver.\n\nBefore exiting, remember to close the driver and stop the proxy:\n\n```java\ndriver.quit();\nproxy.stop(); \n```\n\nIf you're having any trouble integrating Oxylabs’ Residential Proxies with Selenium and this guide didn't help you – feel free to contact our customer support at support@oxylabs.io.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fselenium-proxy-integration-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxylabs%2Fselenium-proxy-integration-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxylabs%2Fselenium-proxy-integration-java/lists"}