Firefox selenium webdriver gives "Insecure Connection" - java

I've created a Maven project with 20 tests made with Selenium Webdriver (java). Now, when I want to execute my Maven project, I get sometimes the following error:
Mozilla error
This is due to login every test. So, when I want to run 20 tests, sometimes that error appears and I can't continue my test, so it returns "Failed test" in Selenium Webdriver.
Does anybody know how to fix this problem?
I've tried to put "Thread.sleep(30000);" at the end of every test to give them some time "not to seem a robot", but it doesn't work...
Thanks so much for your help guys!

Here is the Answer to your Question:
The Real Issue:
The URL/Connection with which you are a working if it is Not Secure then whenever you access the URL through Mozilla Firefox 53.0, Firefox will display a lock icon with red strike-through red strikethrough icon in the address bar. Now when URL gets loaded the cursor by default will be positioned on Username field and there will be popup showing a message This connection is not secure. Logins entered here could be compromised. Learn More like this:
Now your script through Selenium enters the username within the Username input field and the Not Secure popup overlays the Password input field.
Next if you try to call the click() or sendKeys() operation in the Password input field the Not Secure popup receives the click and Insecure password warning in Firefox page opens up in the next tab along with Selenium shifting its focus to new tab. Hence test-case starts Failing.
Solution:
In these cases the best solution is:
Create a new Mozilla Firefox Profile. You will find the documentation here. For Example, I have created a Firefox Profile by the name debanjan
Configure the Firefox Profile debanjan to ignore all the UntrustedCertificate issues.
Rerun your Test Script without any issues.
Here is a sample code block to disable insecure_field_warning:
System.setProperty("webdriver.gecko.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
FirefoxProfile testprofile = profile.getProfile("debanjan");
testprofile.setAcceptUntrustedCertificates(true);
testprofile.setAssumeUntrustedCertificateIssuer(true);
testprofile.setPreference("security.insecure_field_warning.contextual.enabled", false);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, testprofile);
dc.setCapability("marionette", true);
WebDriver driver = new FirefoxDriver(dc);
driver.manage().window().maximize();
driver.navigate().to("http://demosite.center/wordpress/wp-login.php");
Let me know if this Answers your Question.

Related

Unable to capture text inside new window in Java Selenium Headless browser

I'm running all my test suites on Jenkins which is deployed on AWS EC2 instance. There is a scenario where when I click on a button, new small window opens up and I'm doing assertion for the text visible inside the small newly opened window. But my tests are failing when I run using Headless mode. But, same scripts works fine when I run scripts locally without opting for headless browser.
The issue here is the scripts are failing because of headless browser since it's unable to capture text inside small window which has opened after click of button.
This class is extending InitiateDriver class which explained. Below class is trying to fetch text which is visible inside the new window which just opened after clicked on SignInWithGSuiteSSOClick() button.
Here is the code:
// click on a button
GSuiteobject.SignInWithGSuiteSSOClick().click();
String winHandleBefore = driver.getWindowHandle();
// Here trying to capture text inside new window opened up basically gmail window to enter email
String signInHeader = GSuiteobject.GsuiteSignInHeader().getText();
Assert.assertEquals(signInHeader, "Sign in");
GSuiteobject.GsuiteEmail().sendKeys("example#gmail.com");
InitiateDriver.java
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1920, 1080");
options.addArguments("--disable-gpu");
driver = new ChromeDriver(options);
The same code works in browser mode but not in headless. But the driver will be initialized but it fails only while capturing text. Please help me out I'm stuck here and unable to execute it on Jenkins as a headless browser.
Headless chrome browser's gmail UI will be different from actual gmail UI(latest). Hence it fails when we run headless chrome for automating gmail login since xpaths will differ. We can validate that by taking Screenshot by running on headless and normal browser.
I suggest to take screenshot using both headless and normal browser. To check on xpaths for headless we can try driver.getPageSource() method.

Unable to sendkeys/click with selenium Java or JavascriptExecutor

These are the steps that my code is running.
I start the chromedriver with the secure shell appt - no issues, it launches the browser and appt correctly
chromeOptions.addExtensions(new File("src/test/resources/win32/browserprofile/Secure-Shell-App_v0.8.43.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
I then navigate using driver get to the chrome URL setup page to send connection data.
driver.get("chrome-extension://pnhechapfaindjhompbnflcldabbghjo/html/nassh.html");
While on this page from the image below, I tried to send keys or click on any of the fields with sendkeys or click and I get the following error.
I have tried multiple ways and im getting the same results: org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null
Here is my code
//Webdriver
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("aabb");
driver.findElement(By.id("field-username")).click();
driver.findElement(By.id("field-username")).sendKeys("useridval");
driver.findElement(By.id("field-hostname")).click();
driver.findElement(By.id("field-hostname")).sendKeys("10.0.0.0");
//JavascriptExecutor
// This will execute JavaScript in your script
((JavascriptExecutor)driver).executeScript("document.getElementById('field-username').value='migsrcrfuser';");
Question: Is this even possible, I see an id and the id is unique; furthermore, I also tried xpath and received the same result. Thoughts
Breift description: Terminal emulator and SSH client.
Secure Shell is an xterm-compatible terminal emulator and stand-alone ssh client for Chrome. It uses Native-Client to connect directly to ssh servers without the need for external proxies.
https://chrome.google.com/webstore/detail/secure-shell-extension/iodihamcpbpeioajjeobimgagajmlibd
Update your ChromeDriver to 2.37 (the latest) from https://sites.google.com/a/chromium.org/chromedriver/downloads
I think that you are using Chrome v65
The issue was frame related. I used this code to identified how many frames and then send keys to the correct frame. phew!
int size = driver.findElements(By.tagName("iframe")).size();
System.out.println(size);
driver.switchTo().frame(1); // Switching the inner Frame with 1 0 for outer fram
driver.findElement(By.xpath("//*[#id='field-description']")).sendKeys("9109");

Remember credentials with serenity BDD (using selenium)

Im trying to create test cases with Serenity BDD (using selenium).
I have accepted the fact that between each test case it "restarts" the browser.
And I found a way to not do between Scenarios.
But what Im looking for is to run the test in normal browser mode and not in incognito.
I want the browser to click the "remember me" option, log in, log out, and see username and password in the fields.
But since the tests are running in the browser with incognito mode, the password is blank.
Any suggestions ?
Thank you
You can configure your driver to run on specific profile of browser.
Below is the Mozilla link with steps to configure your profile:
https://support.mozilla.org/en-US/kb/profiles-where-firefox-stores-user-data
Once you have configured that profile you can launch that browser manually and save all the user name and passwords manually.
So next time when you launch this profile of browser user name and password fields will be auto filled.
*ProfilesIni profile = new ProfilesIni();
FirefoxProfile myprofile = profile.getProfile();
WebDriver driver = new FirefoxDriver(myprofile);*

In parallel execution, safari browser navigate to url with out login page automatically

I am using selenium web driver 2.48 and safari driver 2.48 and safari version 8.0.8
I am facing a problem on running my test execution in safari driver.The problem is
"In parallel execution, if in one safari window,login is successfull, than in other
safari windows, this login page is not shown,
that means safri navigate to url with
out login as one safari window already complete login."
and for this reason, i am facing below issue in parallel execution:
"CSRF verification failed.Request aborted"
I want like that for parallel execution:
if five safari browser window open, in each window, login page will be appeared.
In a sense, each safari driver instance will not share other safari driver
instances resources or any other thing
I have changed safari preferences settings but its not helping.
Is there any best way to declare safari driver or i need to add any desired capabilities or
any other things in safari preferences or any any good suggestion.
please and thanks.
i am using the following code:
SafariOptions safariOptions = new SafariOptions();
safariOptions.setUseCleanSession(true);
DesiredCapabilities dc = DesiredCapabilities.safari();
dc.setCapability(SafariOptions.CAPABILITY, safariOptions);
currentDriver = new SafariDriver(dc);
Set<Cookie> cookies = currentDriver.manage().getCookies();
currentDriver.manage().deleteAllCookies();
if(!cookies.isEmpty())
{
Iterator<Cookie> iter= currentDriver.manage().getCookies().iterator();
while(iter.hasNext()){
Cookie C = iter.next();
}
cookies.clear();
}
I personally have not used safari before. And as you said that the behavior in all other browsers are as you expect it to be. I would like you to try the following.
There is a way by which you can specify the profile of the driver instance to be used. I would suggest you to create separate profiles for each instance and try out . How to do that is explained in this answer. This answer explains how to use same profile each time . You need to use a different profile each time. ( Which happens by default in chrome not sure why it wouldn't for safari )

When i run selenium webdriver code Firefox webdriver not starting through given webaddress

When i tried to start on Firefox web driver its not starting its showing firefox default page
WebDriver dr = new FirefoxDriver();
dr.get("https://www.google.co.in/");
dr.manage().window().maximize();
its not starting its showing firefox default page
Below i attach output image screenshot
https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/
Firefox is one of the most compatible browsers with selemium, and at the same time, is one of the least compatible.
I say this because if you do not have the correct version of the selenium library to go with the version of firefox you are running, or vice-versa, it will always fail.
I would start by attempting to switch to a different version of Firefox. Selenium version 2.48.0 supports Firefox versions 24-41, so if your firefox version does not fit within that range, it is more than likely the problem.
I faced the same issue. The solution to this problem is to update the selenium version. When the page u mentioned i.e https://www.mozilla.org/en-US/firefox/43.0.4/firstrun/learnmore/ opens on firefox launch go to Options -> Addons -> Extensions. You will be able to see the Error there. I got "Forefox Webdriver could not be loaded and is disabled".
This was on Firefox 43 with selenium 2.44. Updating to selenium 2.51 rectified the issue.
Sorry, I cannot comment yet but I would like to help. I got the similar issue when I used selenium webdriver integrated in my python script. The problem was with credentials (particularly with the SSL protocols while declaring a new webdriver object). The code I used looked as the following:
driver = webdriver.PhantomJS(executable_path = "/opt/local/bin/phantomjs", service_args=['--ignore-ssl-errors=true'])
As you can see I use a key that ignores ssl errors. This solved my issue, so I am not sure what platform you use to write the code but hope you can find the similar call for the object.
I found the way how people handle untrusted certificates here. Particularly, for FireFox:
//It creates firefox profile
FirefoxProfile profile=new FirefoxProfile();
// This will set the true value
profile.setAcceptUntrustedCertificates(true);
// This will open firefox browser using above created profile
WebDriver driver=new FirefoxDriver();
driver.get("pass the url as per your requirement");
Hope it helps you!
Best.
-Petr.
Try this.. This will resolve the issue..
FirefoxProfile fpi = new FirefoxProfile();
fpi.setPreference("browser.startup.homepage_override.mstone", "ignore");
fpi.setPreference("startup.homepage_welcome_url.additional", "about:blank");
wd = new FirefoxDriver(fpi);
wd.get("http://www.google.com");
if you want to over-ride the properties of firefox, then,
1.first to find the list of browser properties, type "about:config" in the address url
2.use, setPreference method to set/assign the values..

Categories

Resources