I use WebDriver Java bindings. Creating a FirefoxDriver instance launches the Firefox browser with the 'firstrun' page: https://www.mozilla.org/en-US/firefox/42.0/firstrun/learnmore/ . It takes some time to load this page.
I want Firefox to start from "about:blank" to make the initialization faster. For Internet Explorer this can be done by:
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(InternetExplorerDriver.INITIAL_BROWSER_URL, "about:blank");
new InternetExplorerDriver(cap);
How to do the same for Firefox and Chrome?
Firefox:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.homepage", "about:blank");
profile.setPreference("startup.homepage_welcome_url", "about:blank");
profile.setPreference("startup.homepage_welcome_url.additional", "about:blank");
WebDriver driver = new FirefoxDriver(profile);
Related
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);
I am trying to log in into a website using selenium.The end site provides a access denied message if i enter wrong credentials and submit the login form(without selenium).But when i do the same stuff using selenium,the access denied message does not appear. Any suggestions?
URL : https://oa.lombardfinance.com.au/
ChromeOptions options = new ChromeOptions();
options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
JavascriptExecutor js = (JavascriptExecutor)driver;
driver.get("https://oa.lombardfinance.com.au/");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtClientNumber")).sendKeys("Subrat");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtPassword")).sendKeys("Subrat");
driver.findElement(By.id("ctl00_ContentPlaceHolder1_txtCaptcha")).sendKeys("Subrat");
//WebElement loginForm = driver.findElement(By.id("aspnetForm"));
//js.executeScript("arguments[0].submit();", loginForm);
WebElement login = driver.findElement(By.id("ctl00_ContentPlaceHolder1_btnLogin2"));
new Actions(driver).moveToElement(login).click().perform();
Just tried the same code you're using with a slight difference in driver initiation:
System.setProperty("webdriver.chrome.driver", "\path\to\chromedriver.exe");
WebDriver driver = new ChromeDriver();
I excluded the line:
options.addArguments("disable-infobars");
and the Selenium test shows Access denied as well.
Try using the below code:
System.setProperty("webdriver.chrome.driver", "\\path\\to\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--test-type");
options.addArguments("--disable-extensions");
WebDriver driver = new ChromeDriver(options);
The solution is more convenient one because some times browser shows developer mode issue.
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.
I'm trying to tell the org.openqa.selenium.firefox.FirefoxDriver of Selenium to use an existing profile along with its cookies and proxy settings, so I'm doing:
FirefoxProfile firefoxProfile = new FirefoxProfile(new File("C:\\Users\\name\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\u72231ej.other"));
WebDriver driver = new FirefoxDriver(firefoxProfile);
But it seems that a new profile is created no matter what.
FirefoxProfile ffprofile = new FirefoxProfile();
ffprofile.setPreference(); //Set your preference here
FirefoxDriver driver = new FirefoxDriver(ffprofile);
You can get the list of preferences by typing about:config in the firefox address bar.
New driver will have a profile with your settings applied.