certificate import selenium webdriver - selenium

Before running selenium there is a requirement that a certain certificate needs to be imported. On importing the same the execution starts as expected.
But each and everytime the execution re-starts (a new test suite is run), the certificate is no longer present in Firefox and hence fails as the certificate is not imported.
Is there any setting in selenium that will prevent the certificate from being unimported before the execution starts everytime/
-S

Create a new Firefox profile, import all your certificate in that profile and then use that profile while instantiating Firefox webdriver instance.
To create new Firefox profile refer this link.
Once you import your certificate to newly created profile, use below code to create Firefox webdriver instance:
ProfilesIni profile = new ProfilesIni();
FirefoxProfile profile = profile.getProfile("your_profile_name");
WebDriver driver = new FirefoxDriver(profile);

There are many ways to setup a FireFox profile in Selenium. You can setup a specific profile to use as #Surya mentioned above, or you can set setAcceptUntrustedCertificates to true for your profile:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
WebDriver driver = new FirefoxDriver(profile);
Other methods that I've seen using a RemoteWebDriver involve wrapping your profile in DesiredCapabilities which also has a flag for accepting SSL certificates:
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(capabilities);
Without seeing how you've setup your profile, we're only taking shots in the dark. Hopefully one of these suggestions works for you.

Related

Selenium window taking existing cookies and directly logging into application

I am trying to automate login to my project application which has login enabled through SSO. In my existing chrome window which I am using to inspect the webelements, I have logged into the application with my credentials.
With the same credentials I am trying to automate the login process. However, when I run my script after initializing the Chrome Driver, my Selenium window is directly opening the home page i.e. the page which loads after users successfully logs in to the application. The login window is not coming. On doing driver.get(applicationURL), the application is directly navigating to the landing page and not the login page.
I am assuming it is using the existing cookies/cache to login. However, my understanding is Selenium initiated windows are without any existing cookies or cache.
When I try running the same script on Chrome icognito mode, then the login window is opening.
This is my browser initialization code -
public static WebDriver driver;
System.setProperty("webdriver.chrome.driver", TestUtil.CHROMEDRIVER_PATH);
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-infobars");
options.addArguments("--start-maximized");
options.addArguments("--disable-gpu");
options.addArguments("--no-sandbox");
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
System.out.println("URL Is "+prop.getProperty("url"));
driver.get(prop.getProperty("url"));
driver.manage().timeouts().implicitlyWait(TestUtil.IMPLICIT_WAIT, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(TestUtil.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(TestUtil.SET_SCRIPT_TIMEOUT, TimeUnit.SECONDS);
return driver;
**Chrome Version is - 108.0.5359.95 **
Chrome Driver version is 108.0.5359.71
can you use
options.addArguments("--no-sandbox", "--disable-dev-shm-usage")
instead of
options.addArguments("--no-sandbox")

Why is Selenium webdriver is not opening webpage?

Hi i am trying to connect to remote webdriver on browserstack using Selenium but whenever the page loads in Chrome and Firefox i get a security message (see images below).
my URL is starting with https:// (when i manually open the browser i have to accept the certificates and continue before the webpage loads)
i have added this line to my code but it does not seem to make any difference:
capability.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capability.setCapability(CapabilityType.SUPPORTS_NETWORK_CONNECTION, "true");
capability.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
NOTE: This issue only occurs then the tests are run on the GoCD pipeline. when running on intellij it all works fine
error:
org.openqa.selenium.WebDriverException: Reached error page: about:neterror?e=nssFailure2&u=https%3A//transport....
in chrome i see this:
and in firefox i get a similar message:
Can you try adding something as below and test:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("ignore-certificate-errors");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
options.addArguments("--test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArguments("disable-gpu");
chromeOptions.AddArguments("window-size=1980,1080");
Driver = new ChromeDriver(chromeOptions);
i have found the problem for anyones future reference.
This is because DNS requests were not forwarded for our host name on GocD.

How to set browser language in selenium remote webdriver capabilities

I need to start Firefox / Chrome using remote webdriver with a specific browser language. I know how to do it while running locally. But is it possible to start a remote webdriver with specifying browser language.
This is how object creation done is RemoteWebDriver,
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), DesiredCapabilities.firefox());
Profiller is the key here,
var fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-au");
desiredCap.SetCapability(FirefoxDriver.ProfileCapabilityName,fp.ToBase64String());
your code seems specific to chrome so you can use this, I hope this might help you,
var options = new ChromeOptions();
options.AddArgument("--lang=zh"); // this sets US english
desiredCap.SetCapability(ChromeOptions.Capability, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:PORT_NUMBER/"), desiredCap.chrome());
Possible duplicate of How to set Browser Language using RemoteWebDriver

How to handle SSL certificate for Firefox, Chrome and IE browsers using Selenium 3.4.0 standalone

My application has both http and https ssl certificate. To handle https link using Selenium 3.4.0 I have used following code for firefox. Firefox browser is opening, but it is showing 'Secure Connection Failed'
System.setProperty("webdriver.gecko.driver","C:\\Users\\vidhya.r\\Desktop\\Automation\\Jars\\geckodriver.exe");
FirefoxProfile pro = new FirefoxProfile();
pro.setAcceptUntrustedCertificates(true);
WebDriver driver = new FirefoxDriver(pro);
driver.get("https://192.168.8.115:7077/final/#!");
Below solution will definitely work for your chrome browser.
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
System.setProperty("webdriver.chrome.driver",
System.getProperty("user.dir")+"/Drivers/chromedriver.exe");
driver = new ChromeDriver(options);
driver.get(applicationURL);
driver.manage().window().maximize();

How do you start selenium using Chrome driver and all existing browser cookies?

From what I understand so far, Chrome Driver always starts without any stored browser cookies.
I need the driver start with all the cookies stored by Chrome.
I wonder if there is any way to start the driver with the cookies that are already stored? I'm using C# with .net 4.5.
Yes we can do it by invoking saved chrome profile just like firefox profile. below are steps i noted when i am doing bit back ago
in Java, we can do it by using ChromeOptions and Chrome Profile. In chrome navigate to chrome://version/ It will display profile path and Executable path.
As per my working on this, The profile path is \Local\Google\Chrome\User Data\Profile 3 This is displaying what is displayed when i navigate to chrome://version/ in normal chrome browser. In this profile, i navigated to stackoverflow and saved credentials. So used below code
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("binary", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
System.setProperty("webdriver.chrome.driver", "E:\\selenium_setups\\poi-3.12\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
options.addArguments("user-data-dir=C:\\Users\\murali\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 3");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
//WebDriver driver = new ChromeDriver(options);
driver.get("http://stackoverflow.com/");
As per my understanding, i excepted stackoverflow.com page displayed as logged in. but for first time, i am not logged in. so cross checked with chrome://version/ in chrome opened by driver, profile path is displayed as
\Local\Google\Chrome\User Data\Profile 3\Default . then logged manually in that profile it self, which is opened by webdriver and executed gain by closing it.
Finally, page is displayed as logged in. So it may be in java, i hope it will helps you to try in C# .