Selenium opening browser but not loading websites in Java - java

I am using Selenium in a Burp plugin but I can't load pages with the get method. Browsers open correctly, both Firefox and Chrome, but they don't load the page. Chrome address bar shows "data;.", while Firefox has no text in it. I am using the last driver available, Chrome 81.0.4044.183 and the driver for this exact version, while Firefox is 76.0.1 and I am using GeckoDriver 0.24 (since 0.25+ have a known bug) and it works with the last version of Firefox.
The code is the following
void runBrowserAutomatization(File fileDriver, String seleniumTrack, boolean isHeadless) {
WebDriver driver;
if (gui.usedBrowser().toLowerCase().contains("chrome")) {
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.chrome.driver", fileDriver.getPath());
driver = new ChromeDriver(options);
} else if (gui.usedBrowser().toLowerCase().contains("firefox")) {
FirefoxOptions options = new FirefoxOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("localhost:8080");
proxy.setSslProxy("localhost:8080");
options.setCapability(CapabilityType.PROXY, proxy);
options.setHeadless(isHeadless);
System.setProperty("webdriver.gecko.driver", fileDriver.getPath());
driver = new FirefoxDriver(options);
} else {
PrintMsg("No browser selected...");
return;
}
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://www.nytimes.com/");
driver.quit();
}
I may also think it is a Proxy misconfiguration, Burp certificate is installed in Firefox and Windows (where Chrome gets Certificate Authorities) but is not shown in the settings of the instance started by Selenium. Any help or suggestion is highly appreciated, thnaks.

Related

How to connect proxy to Selenium Chrome with authorization?

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/");

Login failed message does not appear on a website while using selenium

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.

Firefox Error: "Your connection is not secure" while launching driver with Selenium 3.0.1 using Java

My Firefox version is 46.0.1 and Selenium version is 3.0.1.
I am getting error:
Your connection is not secure
while executing following code:
#Test
public void test() {
ProfilesIni profile = new ProfilesIni();
FirefoxProfile ffProfile = profile.getProfile("newCretedProfile");
ffProfile.setAcceptUntrustedCertificates(true);
ffProfile.setAssumeUntrustedCertificateIssuer(false);
System.setProperty("webdriver.gecko.driver", "D:\\SELENUIUM\\Drivers\\geckodriver.exe");
FirefoxDriver driver = new FirefoxDriver(ffProfile);
driver.get("http://www.google.com");
driver.quit();
}
I have created new firefox profile and followed steps from this url
Nevertheless it's not working and giving me same error while I launching any site.
Download Firefox 55 beta and set
capabilities.setCapability("acceptInsecureCerts", true);
Here is my code that works for Firefox 55 beta:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("firefox");
capabilities.setCapability("acceptInsecureCerts", true);
RemoteWebDriver driver = new RemoteWebDriver(Environment.remoteWebDriverURL, capabilities);
I have tried this approach and it worked well for me.
Create new firefox profile by following below step.
Close all your firefox windows
In the Run dialog box, type in: ‘firefox.exe -p' and then Click OK.
Click “Create Profile”
Create a name for your new profile(say Selenium)
Click “Choose Folder”
Pick location something easy to find — like “C:\NewFirefoxProfile”
Click Finish
Now after selecting newly created profile, start Firefox. Open the specific url you were getting 'Secure Connection Issue', accept SSL certificates for this profile.
Now use the newly created firefox profile to run your selenium test. Modify below code as per your requirement.
System.setProperty("webdriver.firefox.marionette","D:\\SELENUIUM\\Drivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile("C:\\NewFirefoxProfile");//location of your new firefox profile
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("https://cacert.org/");
With FF v53+ and Se 3.x (summer 2017), advice from before (May?) 2017 is no longer true.
You have to use Marionette and set capability to True.
Took me few days to sort out all old and obsolete advice, yours for free. :-)
Looks like it is not supported yet by geckodriver/Marionette.
You can check below bugs for more information:-
https://github.com/mozilla/geckodriver/issues/93
https://bugzilla.mozilla.org/show_bug.cgi?id=1103196
If you want to run the tests on Firefox with Selenium 3.0 set the Firefox driver capability “marionette” to false.
#Test
public void test() {
DesiredCapabilities d = new DesiredCapabilities();
d.setCapability("marionette", false);
WebDriver driver = new FirefoxDriver(d);
driver.get("http://www.google.com");
driver.quit();
}

How to turn off the proxy settings on chrome browser through selenium webdriver?

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.

How to set Google Chrome in WebDriver

I am trying to set Chrome as my browser for testing with Web-Driver and set the chromedriver.exe file properly but I am still getting the following error:
org.openqa.selenium.WebDriverException:
The path to the driver executable must be set by the webdriver.chrome.driver system property;
for more information, see http://code.google.com/p/selenium/wiki/ChromeDriver.
The latest version can be downloaded from http://code.google.com/p/chromedriver/downloads/list
I have already checked the path of the driver but still i am getting same error.
I don't know where i have made a mistake.
Here is my code:
File file = new File("C:\\chromedriver.exe");
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Capability= DesiredCapabilities.chrome();
Capability.setBrowserName("chrome");
Capability.setPlatform(Platform.LINUX);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
browser.get(webUrl);
Please help me!!
Aditya,
As you said in your last comment that you are trying to access chrome of some other system so based on that you should keep your chrome driver in that system itself.
for example: if you are trying to access linux chrome from windows then you need to put your chrome driver in linux at some place and give permission as 777 and use below code at your windows system.
System.setProperty("webdriver.chrome.driver", "\\var\\www\\Jar\\chromedriver");
Capability= DesiredCapabilities.chrome(); Capability.setPlatform(org.openqa.selenium.Platform.ANY);
browser=new RemoteWebDriver(new URL(nodeURL),Capability);
This is working code of my system.
I'm using this since the begin and it always work. =)
System.setProperty("webdriver.chrome.driver", "C:\\pathto\\my\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");
For Mac -Chrome browser
public class MultipleBrowser {
public WebDriver driver= null;
String browser="mozilla";
String url="https://www.omnicard.com";
#BeforeMethod
public void LaunchBrowser() {
if(browser.equalsIgnoreCase("mozilla"))
driver= new FirefoxDriver();
else if(browser.equalsIgnoreCase("safari"))
driver= new SafariDriver();
else if(browser.equalsIgnoreCase("chrome"))
System.setProperty("webdriver.chrome.driver","/Users/mhossain/Desktop/chromedriver");
driver= new ChromeDriver();
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
driver.navigate().to(url);
//driver.manage().deleteAllCookies();
}
It was giving Illegal Exception.
My workaround with code:
public void dofirst(){
System.setProperty("webdriver.chrome.driver","D:\\Softwares\\selenium\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.facebook.com");
}
Mac OS:
You have to install ChromeDriver first:
brew cask install chromedriver
It will be copied to /usr/local/bin/chromedriver. Then you can use it in java code classes.
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","Absolute path of Chrome driver");
driver =new ChromeDriver();
baseUrl = "URL/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}

Categories

Resources