How to set Proxy Authentication in seleniumWebdriver for Chrome Browser

后端 未结 5 564
忘了有多久
忘了有多久 2021-01-05 17:58

I\'m trying to Automate a web application selenium 2.0 [webdriver+java].The web application is currently deployed in our UAT servers on our local network.My test cases are e

5条回答
  •  醉酒成梦
    2021-01-05 18:31

    Simple method to add authenticated proxy using selenium wire in Both firefox and chrome

    In python

    Step:1

    pip3 install selenium-wire
    

    Step:2

    from seleniumwire import webdriver
    from selenium import webdriver
    

    step:3

    Add proxy in below-mensioned format

    proxy= "username:password@ip:port"
            options = {'proxy': {'http': proxy, 'https': proxy, 'no_proxy': 'localhost,127.0.0.1,dev_server:8080'}}
    

    step:4 pass proxy as an argument

    CHROME

    driver = webdriver.Chrome(options=chrome_options, executable_path="path of chrome driver", seleniumwire_options=options)
    

    Firefox

    driver = webdriver.Firefox(seleniumwire_options=options, executable_path="path of firefox driver", options=firefox_options)
    

    step:5 Verify proxy applied by requesting the url https://whatismyipaddress.com/

    time.sleep(20)
    driver.get("https://whatismyipaddress.com/")
    

    Note: But selenium log shows it runs in without proxy because we are using an external package to apply proxy.

提交回复
热议问题