Is there a way to enable a proxy on running Google Chrome (for example after I log in to my mail)?
Yes this is possible:
PROXY = "proxy-here" # IP:PORT or HOST:PORT
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(chrome_options=chrome_options)
chrome.get("http://whatismyipaddress.com")
how do i set proxy for chrome in python webdriver
Related
I am a newbie in using selenium. When I use proxy chrome shows there is no internet connection. I have checked my internet connection and looked for possible solutions on the internet but failed. I also restarted my computer but it did not work.
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from time import sleep
PROXY = '43.225.164.59:38829'
options = Options()
options.add_argument('--proxy-server=%s' % PROXY)
driver = webdriver.Chrome(options = options,
executable_path='C:\webscraping\chromedriver')
driver.get('https://whatismyipaddress.com/')
sleep(6)
driver.close()
The code is looking good, it should works.
Do you use proxy with authentification? If do, you should use another way to enable proxy - issue (Selenium doesn't support authentification of proxy).
You should also be sure, that proxy is working. Check it with curl:
If you're using public proxy:
curl https://2ip.ru/ -x "http://proxy_host:proxy_port"
If you're using private proxy with authentification:
curl https://2ip.ru/ -x "http://proxy_user:proxy_pwd#proxy_host:proxy_port"
Both of these commands will return your ip address (it should be equal to proxy address you use.
While running simple selenium test in google chrome, got below error. (Windows 10)
Starting ChromeDriver 75.0.3770.90 (a6dcaf7e3ec6f70a194cc25e8149475c6590####-refs/branch-heads/3770#{#XXXX}) on port XXXXX
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
If I understand it correctly, we can have a server machine running Selenium+Chrome+Chrome driver,
and a client machine that uses the RemoteWebDriver:
On the server we execute this:
$ java -jar selenium-server-standalone-{VERSION}.jar
On the client, we have a Java program with something like:
WebDriver driver = RemoteWebDriver.builder()
.addAlternative(new ChromeOptions())
.setCapabilitiy("proxy", new Proxy())
.build();
driver.get("http://example.com/");
However, how does the client know the ip and port of the server?
Ref:
https://seleniumhq.github.io/docs/remote.html
https://github.com/SeleniumHQ/selenium/wiki/RemoteWebDriver
Set the URL on the RemoteWebDriver to your server.
WebDriver driver = RemoteWebDriver.builder().url(new URL("https://here.com:1234")).build()
I'm trying to setup selenium standalone chrome service to test my Codeception suit.
I run chrome standalone as a service:
services:
- mysql:latest
- selenium/standalone-chrome:latest
And then I setup the connections for my Codeception test uses WebDriver with an extension for WordPress:
WPWebDriver:
url: 'http://localhost'
host: 'selenium__standalone-chrome'
browser: chrome
port: 4444
restart: true
wait: 2
adminUsername: admin
adminPassword: 1234
adminUrl: /wp-admin
All other tests run well but when it comes to the suite where I use Selenium it refuses to connect:
Time: 7.55 seconds, Memory: 16.00MB
There was 1 failure:
---------
1) SampleTestCept: Test if wp is working in selenium
Test tests/php/acceptance/SampleTestCept.php
Step See "Just another WordPress site"
Fail Failed asserting that on page /
--> This site can’t be reached
localhost refused to connect.
Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
Reload
DETAILS
--> contains "this site can't be reached".
Scenario Steps:
2. $I->see("This site can't be reached") at tests/php/acceptance/SampleTestCept.php:6
1. $I->amOnPage("/") at tests/php/acceptance/SampleTestCept.php:4
Any ideas of what am I doing wrong?
Use environment variable HOSTNAME, to find gitlab runner actual hostname.
I worked around this by replacing 'localhost' in your webdriver config by the ip-address of the gitlab runner. You might want to check out my blog post about running codeception tests on gitlab-ci.
Probably the issue is that you are using http://localhost url and running selenium server on separate host.
Selenium tries to connect to port 80 of its own, not of the machine which is running tests.
Running a Selenium 2 RemoteWebDriver server using java -jar selenium-server-standalone-2.15.0.jar.
I always get the error:
HTTP ERROR: 403
Forbidden for Proxy
RequestURI=/session
when connecting to it using the python WebDriver client:
import selenium.webdriver as webdriver
webdriver.Remote('http://localhost:4444', {})
or any other various RemoteWebDriver client I could find.
The solution was simple: Use the pathname /wd/hub
i.e.
import selenium.webdriver as webdriver
webdriver.Remote('http://localhost:4444/wd/hub', {})
Not a solution to the exactly Problem, but for people getting this error:
HTTP ERROR: 403
Forbidden for Proxy
RequestURI=/
Powered by Jetty://
This error appears e.g. if multiple instances of Selenium are running, so you need to shut it down by browsing to URL:
http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer
If another instance was running there should appear okok
You have another process which is bound to same port i.e 4444.
Selenium Grid by default uses port:4444.
You either need to kill the process which is bound to port:4444 or else you need to use another port(below used 5555) for your hub.
Use following in command prompt:
java -jar selenium-server-standalone-2.15.0.jar -role hub -port 5555