I want to use portable google chrome for my selenium testing. I am using DesiredCapabilities object to set proxy in browser.
Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
And for using portable Google chrome i am using this code.
ChromeOptions options = new ChromeOptions();
options.setBinary("C:\\Selenium\\Browsers\\GoogleChromePortable\\GoogleChromePortable.exe");
driver = new ChromeDriver(options);
Now the problem is the constructor of ChromeDriver dont have option for creating driver object using both DesiredCapabilities as well as proxy. i.e. either i can apply proxy or i can use portable chrome.
I want something like this
new ChromeDriver(capabilities ,options);
I found a way
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);
ChromeOptions options = new ChromeOptions();
options.setBinary("D:\\m_ali\\GoogleChromePortable\\GoogleChromePortable.exe");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
System.setProperty("webdriver.chrome.driver", "D:\\m_ali\\chromeDriver\\chromedriver_2.27win32\\chromedriver.exe");
driver = new ChromeDriver(capabilities);
Related
Please, see the screenshot:
When opening the selenium browser, it flashes this, how to automatically enter data at compile time?
Proxy proxyClass = new Proxy();
proxyClass.setHttpProxy(urlAndPort);
proxyClass.setSslProxy(urlAndPort);
proxyClass.setSocksUsername(login);
proxyClass.setSocksPassword(password);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setCapability("proxy", proxyClass);
WebDriver driver = new ChromeDriver(chromeOptions);``
driver.get("https://2ip.ru/");
I have a website that I want to test through automation. My client wants to test the website using a proxy of another country as we can testing manual using Browserc Extension. How we can perform it in selenium using java. Below is the code I tried but how can I check this is the same country that proxy I used.
`
Proxy proxy= new Proxy();
proxy.setHttpProxy("localhost:8888");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.gecko.driver", "G:\\Selenium\\Driver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://vapesuite.co.uk/#/");`
I think the issue is with your code and proxy and it is not working properly.
I have tried the free proxy and it was working fine for me, please see the attached screenshot.
Code Used:
FirefoxOptions options = new FirefoxOptions();
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("network.proxy.type", 1);
profile.setPreference("network.proxy.http", "116.80.41.12");
profile.setPreference("network.proxy.http_port", 80);
profile.setPreference("network.proxy.ssl", "116.80.41.12");
profile.setPreference("network.proxy.ssl_port", 80);
options.setProfile(profile);
WebDriver driver = new FirefoxDriver(options);
driver.get("https://vapesuite.co.uk/#/");
https://free-proxy-list.net/
https://mylocation.org/
if you are using maven this should work for you :
https://maven.apache.org/guides/mini/guide-proxies.html
In Selenium, I am facing some issue when open browser in chrome then full screen is not working.
driver.manage().window().maximize();
driver.manage().window().maximize();
Replace to
driver.manage().window().fullscreen();
And it's working
As per manage().window().maximize() method not maximize a correct window using driver.manage().window().maximize(); to maximize the Chrome Browser is not the optimum way. Instead use ChromeOptions to maximize the Chrome Browser as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
To open Chrome Browser in kiosk mode you can also use:
ChromeOptions options = new ChromeOptions();
options.addArguments("--kiosk");
return new ChromeDriver(options);
As an alternative you can also use the argument window-size as follows:
ChromeOptions options = new ChromeOptions();
options.addArguments("window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
All of my tests are failing due to chrome opening up at a size of 800x600. I've looked at several sites for a solution, but nothing I've tried seems to be working.
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
options.addArguments("--window-size=1920,1080");
DesiredCapabilities cap = DesiredCapabilities.chrome();
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, options);
capabilities.setBrowserName("chrome");
capabilities.setPlatform(Platform.WINDOWS);
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);
You apparently cannot resize the chrome in the headless mode .
If I am not mistaken.
"options.addArguments("--headless");"
I am also assuming you are using chromedriver
https://bugs.chromium.org/p/chromedriver/issues/detail?id=1625#c39
The -- is not needed for Java.
options.addArguments("window-size=1920,1080");
How to set the browser window size when using `google-chrome --headless`?
In selenium grid, i use the following code which is working for me.
ChromeOptions options = new ChromeOptions();
options.addArguments(Arrays.asList("--window-position=0,0"));
options.addArguments(Arrays.asList("--window-size=1840,1080"));
When I navigate to my url on chrome, I get The system cannot find the file specified." . I thought it might be due to automatic proxy settings on chrome.
I want to explicitly turn off the proxy setting before starting chrome browser in selenium. I tried below, it isn't working. Can anyone help me
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability("chrome.setProxyByServer", false);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
WebDriver driver = new ChromeDriver();
No errors are thrown at any point of time but URL doesn't open up
Tia
Anjana
You need to pass the options object to the chrome driver when you initialize it. If you use a specific capability then pass it to the chromeDriver(), so that chrome knows what to start with. Also there is no JSON object as setProxyByServer in chrome, instead use noProxy JSON object. Check this out. Here's how -
Proxy proxy=startProxy();
proxy.setProxyType(ProxyType.MANUAL);
proxy.setNoProxy("");
ChromeOptions options = new ChromeOptions();
DesiredCapabilities dc = DesiredCapabilities.chrome();
dc.setCapability(CapabilityType.PROXY, proxy);
System.setProperty("webdriver.chrome.driver",sChromeDriverPath);
dc.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(dc);
More info about chrome capabilities. Hope it helps.