Selenium window taking existing cookies and directly logging into application - selenium

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

Related

Chromedriver - IE Tab permission not granted

I am testing web application. In my test I check client data. For use this test I need IE Tab in chromedriver. I'm initializing chromedriver with IETab correctly. After that page is display with below popup
With popup in console I see below log:
Uncaught IETABAPI Error: Permission not granted. You must call window.ietab.requestAccess to use the IE Tab Api.
I clik Allow and nothing's gonna happen. Correctly test should opening new bookmark in chromedriver. Below my code which is executing chromedriver with IETab.
default void ChromeExtensionIETab() {
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("C:\\Users\\user\\Dysk Google\\all\\testowanie\\chromedriver_win32\\extension_12_4_4_1.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
options.addArguments("--use-fake-ui-for-media-stream");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\user\\Dysk Google\\all\\testowanie\\chromedriver_win32\\chromedriver.exe");
setDriver(new ChromeDriver(options));
getDriver().get("https://api-test/");
getDriver().manage().window().maximize();
getDriver().manage().timeouts().implicitlyWait(18, TimeUnit.SECONDS);
}
Can someone explain me what should I do?
The Enterprise version of IE Tab includes permissions that would otherwise have to be manually enabled by your end users. Read more here.
If IE Tab is installed:
Click here to allow IE Tab to access https:// URLs and file downloads
Enterprise customers please contact us at support#ietab.net to discover how to deploy these settings automatically.
What we don't see is the web page that you are "driving".
The pop-up you are seeing is from the IE Tab api which must first call window.ietab.requestAccess and wait for the result before calling window.ietab.openWithIETab.
The error you are seeing is because the page called window.ietab.openWithIETab without waiting for a response form requestAccess.
So the web-page is probably calling both calls without waiting for the result from requestAccess, perhaps because the developer had already allowed access so they aren't aware that this pop-up is showing any more.

Selenium Webdriver run as administrator

I have developed a tool using Selenium webdriver. I am using the Chrome driver. I was wondering if its possible to run the Chrome browser that launches as administrator.
I cannot log in to the machine using the administrator account, but the administrator has allowed the use of 'Run as Administrator' without putting in the admin credentials. I am not technically sure how this is set up in the company.
The requirement that I'm doing needs to have the browser running as administrator.
Is this set up using System.setProperty or something else?
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "/src/drivers/chromedriver.exe");
WebDriver driver = new ChromeDriver();
WebDriverWait wait = new WebDriverWait(driver, 15);

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# .

browser not opening in client side using selenium web driver

I want to open Chrome on the client side using selenium webdriver. I have a piece of code and it works fine for single system, but I can't access it in another system.
I am using selenium-server-standalone-2.44.0.jar, chromedriver for the purpose.
This is the code I use to open browser:
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
driver=new ChromeDriver();
Is the ChromeDriver on the other system in the same place as on the single system?
Try something like the following (in java):
String currentDir = System.getProperty("user.dir");
String chromeDriverLocation = currentDir + "/../tools/chromedriver/chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromeDriverLocation);
ChromeOptions options = new ChromeOptions();
options.addArguments("test-type");
options.addArguments("disable-plugins");
options.addArguments("disable-extensions");
WebDriver chrome = new ChromeDriver(options);
chrome.get("http://www.google.com");
Selenium webdriver can be used in different languages.
I can give you an example.
A web application is developed by using python in back-end and front-end is built up with html and a interpreted programming language like javascript. If we use selenium webdriver with python then browser opens at server side. and if we use selenium with javascript then browser opens at client side.

handle JS alert using IE webdriver, Selenium

I need to click on a cancel button for a Java based application.
I am using IE Driver, Eclipse IDE and my application only supports IE.[i am scripting in Java]
Here is the situation,
Login to the application
There is a account session popup[confirmation box][js]
[The alert has the focus, user cannot focus the application]
Click on the cancel button
Now, i have logged in successfully but i am unable to handle the JS Alert window.So i am unable to write further scripts.
Kindly help me out !!!
If you're using Java, and you're using the Selenium WebDriver API, something like the following code should work:
driver.switchTo().alert().dismiss();
Alert handling has not been implemented for every driver, but it should work for IE.
Remember you can always find the Javadocs for the WebDriver API at this link.
To Handle Alert in IE, you need to set the capabalities for IE first:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability("ignoreProtectedModeSettings", true); //added this to ignore protecion mode setting so as to launch IE
driver = new InternetExplorerDriver(capabilities);
driver.get("url");
driver.switchTo().alert().dismiss(); //or
driver.switchTo().alert().Accept(); // accordingly