我正在尝试运行我的Selenium Java代码来测试网页。但是由于网络限制,网页无法加载。当我手动设置代理并在浏览器中单击URL时,它可以正常工作。现在,我需要在运行selenium代码时传递那些代理设置。请帮我。
我尝试下面的代码,但仍然显示相同的错误:
Proxy p=new Proxy(); // Set HTTP Port to 7777 p.setHttpProxy("www.abc.com:8080"); // Create desired Capability object DesiredCapabilities cap=new DesiredCapabilities(); // Pass proxy object p cap.setCapability(CapabilityType.PROXY, p); // Open firefox browser WebDriver driver=new ChromeDriver(cap);
问题已通过以下代码解决-
Proxy proxy = new Proxy(); proxy.setHttpProxy("yoururl:portno"); proxy.setSslProxy("yoururl:portno"); DesiredCapabilities capabilities = DesiredCapabilities.chrome(); capabilities.setCapability("proxy", proxy); ChromeOptions options = new ChromeOptions(); options.addArguments("start-maximized"); capabilities.setCapability(ChromeOptions.CAPABILITY, options); driver = new ChromeDriver(capabilities);