Hide browser bot during code execution display at end selenium VBA - vba

I am trying to find a way that enables me to hide the driver (bot) of the selenium in VBA during the execution of the code and display it at end
I can hide it using this line
bot.AddArgument "--headless"
But how I restore it?

No, it won't be possible to make Chrome operate initially in headless mode and then switch back to normal mode within the same session.
When you configure an instance of a WebDriver with Options() to span a new Browsing Context the configuration gets baked within the driver executable which will persist for the lifetime of the WebDriver and being uneditable. So you can't modify/add any existing/new configuration through Options() class to the WebDriver instance which is currently in execution.
Even if you are able to extract the Driver and Session attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated Driver and Browsing Session still you won't be able to change the set of attributes of the Driver.
You can find more details in these discussions:
How to set selenium webdriver from headless mode to normal mode within the same session?
Change ChromeOptions in an existing webdriver
How do I make Chrome Headless after I login manually
Credits to undetected Selenium

Related

Reuse session variables while opening a browser with selenium webdriver

When opening a new browser doing
Dim driver As IWebDriver
the session variables are lost, I have thought about saving these variables in xml files to reload them in the webdriver browser, but it really doesn't seem like the best option. Is there a way to pass these session variables to the new browser in Visual Basic and Firefox Driver?
When you configure an instance of a WebDriver using
Dim driver As IWebDriver
the configuration gets baked into the webdriver session and will persist till the lifetime of the WebDriver being uneditable.
Even if you are able to extract the Session attributes e.g. Session ID, Cookies, UserAgent and other session attributes from the already initiated WebDriver still you won't be able to pass them while initiating a new WebDriver session.

Chrome Webdriver detach option in Java

I am using ChromeDriver for Selenium in Java.
I want to leave the browser open after the test is complete. The default behavior is to close the browser.
I have tried the following
options.setCapability("detach", true);
driver = new ChromeDriver(options);
or
options.setExperimentalOption("detach", true);
Neither seems to work. What is the correct way to use this in Java?
According to detach the property description
If false, Chrome will be quit when ChromeDriver is killed, regardless of whether the session is quit. If true, Chrome will only be quit if the session is quit (or closed). Note, if true, and the session is not quit, ChromeDriver cannot clean up the temporary user data directory that the running Chrome instance is using.
which means (AFAIU) that this only controls if you want to keep your browser open or not in case when your WebDriver process is unexpectedly terminated. This does not cover your particular case.
You can just leave your driver active after the test has completed (not quit it) and create new WebDriver object for each new test. However this is not effective approach from performance standpoint.

Can Selenium be used to automate data retrieval from a 3rd party web portal?

I need to automate a manual task to retrieve sales data from a web portal that is not setup for API access.
Can I use a test tool, such as Selenium, to do this task or is there a better solution out there.
I've never used Selenium but it looks easy enough to create record a macro for the button clicks to log in and initiate the download. I also need to trigger the download once a week, notify an email or slack channel if there is an error and then save the file with a specific name including the date.
My hope is that I can do all of this within an test automation tool but willing to explore other options.
Yes it can be implemented. Once you succeed with fetching the data, change your webdriver run option to "Headless", so that Selenium will run at background and will not make the browser visible during runtime. An example for setting headless mode on Firefox:
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.addArguments("--headless")
WebDriver driver = new FirefoxDriver(options); // init driver in headless mode
After that you can use the fetched data in the rest of your program.

why the code //RemoteWebDriver driver= new FirefoxDriver(); is not used instead of //WebDriver driver= new FirefoxDriver()?

Why is the code //RemoteWebDriver driver= new FirefoxDriver(); not used instead of //WebDriver driver= new FirefoxDriver() to create a driver object?
I feel that RemoteWebDriver gives more capabilities for the driver instance than webdriver reference. Can someone clarify this?
WebDriver will start up a web browser on the computer where the code instantiates it. For example. If you write a bit of code, and then run it to see how you are doing, the browser will pop up on your screen and you will see WebDriver begin to manipulate that web browser window (if everything went well!)
With a major exception which I will explain below, RemoteWebDriver will do the same thing; it will open and manipulate a browser window (if everything went well!) Generally speaking, You can actually switch the instatiation of a WebDriver with a RemoteWebDriver (well, there are advanced cases where you might not be able too do this) The major difference is that RemoteWebDriver sends that request to open and control a web browser to a server, so you normally wouldn’t see the browser open and do it’s thing.
Selenium server is the program that runs and waits for RemoteWebDriver connections. You can run it on your local computer to test it out. If you get it set up and running, you’ll be able to create a RemoteWebDriver and see that the Selenium server accepts the connection and allows you to control the web browser window.
The gains from using RemoteWebDriver?
If you can do connect to a local Selenium server, you can be confident that you have the knowledge and skills needed to connect to a remote Selenium server, or even to a paid service like SauceLabs (Hosting Selenium for you) that allows you to run lots of tests on lots of OS’s and lots of browsers without having to actually maintain or install any of them (Linux, Windows 8, Windows 10, MacOS, Andriod, IOS, IE, Firefox, Opera, Safari, Firefox Mobile, etc) You’ll want to look into running tests asynchronously at this point. You don’t have to run them one at a time, so can test a large number of OS/Browser variations in a very short time.
What does it mean when something is used only for client/server communication?
When you uses a Selenium grid with have one hub and multiple clients, you invoke RemoteWebDriver through which you instantiate the server and and make the request to it.
WebDriver is an interface in selenium which extends SearchContext interface (super most interface in selenium)
Where as RemoteWebdriver is a class which implements WebDriver,
We can use RemoteWebdriver, when we going to execute the test in romote environment,(selenium grid).
WebDriver interface will invoke the driver locally,
Currently in automation mostly we are using WebDriver only.
Grid not using widely.
WebDriver driver=new ChromeDriver() ;
driver is the reference variable where used to access chromedriver class.
Using driver instance we can access all the unimplemented methods available in WebDriver interface, also able to access all the properties available in chromedriver class.
For more details
https://www.softwaretestingmaterial.com/webdriver-driver-new-firefoxdriver/

Selenium drivers don't remember user authentication

The application I'm testing requires a login with the user's Google account. Every time I log in, it displays/requires that I select the 'Allow Access' button as if it doesn't remember that I have already added it to my list of Authorized Access for my Google account. This doesn't happen when I test manually, only when I'm running Selenium. Has anyone come across an issue like this or know of a solution? Thanks in advance.
WebDriver driver = selenium_driver.get(); // using chrome driver
baseUrl = defaults.getProperty("base_url"); // this is set to my localhost
helper.ConnectToURL(baseUrl);
When this started happening, I had been using Selenium 2.28.0--since then, I've updated to 2.31.0 but it's exhibiting the same behavior.
Disclaimer: This is currently not possible according to the ChromeDriver wiki. It states in the "Known Issues" section "Cannot specify a custom profile". (https://code.google.com/p/selenium/wiki/ChromeDriver)
At some point when it is fixed, I would suggest creating or using the default chrome profile that has your authorized access set that your test uses whenever it starts up.
According to the ChromeDriver wiki: "By default, ChromeDriver will create a new temporary profile for each session".
Checkout this post for more in depth information regarding capabilities: http://code.google.com/p/chromedriver/wiki/CapabilitiesAndSwitches
I do my work in .NET and Windows; my set up would look something like this:
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.AddArgument("start-maximized");
chromeOptions.AddArgument("user-data-dir=C:\\Users\\username\\AppData\\Local\\Google\\Chrome\\User Data\\Default");
capabilities = DesiredCapabilities.Chrome();
capabilities.SetCapability(ChromeOptions.Capability, chromeOptions);
ChromeDriver chromeDriver= new ChromeDriver(this.Environment.ChromeDriverLocation, chromeOptions);
If you are not limited to using Chrome for your tests you are able to create and use custom profiles using Firefox.