Selenium Webdriver : Suppress IE log info prints on the console - java

Whenever I launch IE using Selenium WebDriver, it displays a log message on the console which is something like below :
Started InternetExplorerDriver server (32-bit)
2.39.0
Listening on port 5555
Is there any way to suppress this log message from not being displayed on the screen?
Thanks,
Sitam

The following snippet provides the logic but untested Java code. You might need to debug a bit.
The documentation is here, which you should have a look.
InternetExplorerDriverService.Builder ieDriverService = new InternetExplorerDriverService.Builder().withSilent(true);
WebDriver driver = new InternetExplorerDriver(ieDriverService.build());

After doing R&D for while I got solution for four major browsers.
Chrome = System.setProperty("webdriver.chrome.silentOutput", "true");
Firefox = System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "null");
IE =
InternetExplorerDriverService.Builder ieDriverService = new InternetExplorerDriverService.Builder().withSilent(true);
System.setProperty("webdriver.ie.driver", "src/main/resources/IEDriverServer.exe");
driver = new InternetExplorerDriver(ieDriverService.build());`
Edge = System.setProperty(EdgeDriverService.EDGE_DRIVER_LOG_PROPERTY,"null");
If anyone know other browser properties to suppress console output feel free to share in comments.

Related

How to Conceal WebDriver in Geckodriver from BotD in Java?

I followed this post on Stackoverflow to disable Firefox WebDriver detection.
Launch Geckodriver:
System.setProperty("webdriver.gecko.driver", geckdriverExecutableFilePath);
File firefoxProfileFile = new File(fullPathOfFirefoxInstallationFolder);
FirefoxProfile firefoxProfile = null;
try {
firefoxProfile = new FirefoxProfile(firefoxProfileFile);
} catch (Exception e) {
e.printStackTrace();
}
I disabled WebDriver:
WebDriver Disabled
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);
// Disables WebRTC
firefoxProfile.setPreference("media.peerconnection.enabled", false);
I disabled Automation Extensions:
Automation Extension Disabled
// Disables Automation Extension
firefoxProfile.setPreference("useAutomationExtension", false);
I added Proxy:
DesiredCapabilities dc = DesiredCapabilities.firefox();
Proxy proxy = new Proxy();
proxy.setHttpProxy(ipAddress + ":" + port);
proxy.setFtpProxy(ipAddress + ":" + port);
proxy.setSslProxy(ipAddress + ":" + port);
dc.setCapability(CapabilityType.PROXY, proxy);
firefoxOptions.merge(dc);
driver = new FirefoxDriver(firefoxOptions);
Yet BotD still detects my browser as being controlled by automation tool.
BotD Detection
How can I solve this?
When using Selenium driven GeckoDriver initiated firefox Browsing Context
The webdriver-active flag is set to true when the user agent is under remote control. It is initially false.
where, webdriver returns true if webdriver-active flag is set, false otherwise.
As:
navigator.webdriver Defines a standard way for co-operating user agents to inform the document that it is controlled by WebDriver, for
example so that alternate code paths can be triggered during
automation.
Further #whimboo in his comments confirmed:
This implementation have to be conformant to this requirement. As such
we will not provide a way to circumvent that.
Conclusion
So, the bottom line is:
Selenium identifies itself
and there is no way to conceal the fact that the browser is WebDriver driven.
Recommendations
However some pundits have suggested some different approaches which can conceal the fact that the Mozilla Firefox browser is WebDriver controled through the usage of Firefox Profiles and Proxies as follows:
selenium4 compatible python code
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
profile_path = r'C:\Users\Admin\AppData\Roaming\Mozilla\Firefox\Profiles\s8543x41.default-release'
options=Options()
options.set_preference('profile', profile_path)
options.set_preference('network.proxy.type', 1)
options.set_preference('network.proxy.socks', '127.0.0.1')
options.set_preference('network.proxy.socks_port', 9050)
options.set_preference('network.proxy.socks_remote_dns', False)
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = Firefox(service=service, options=options)
driver.get("https://www.google.com")
driver.quit()
Potential Solution
A potential solution would be to use the tor browser as follows:
selenium4 compatible python code
from selenium.webdriver import Firefox
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.options import Options
import os
torexe = os.popen(r'C:\Users\username\Desktop\Tor Browser\Browser\TorBrowser\Tor\tor.exe')
profile_path = r'C:\Users\username\Desktop\Tor Browser\Browser\TorBrowser\Data\Browser\profile.default'
firefox_options=Options()
firefox_options.set_preference('profile', profile_path)
firefox_options.set_preference('network.proxy.type', 1)
firefox_options.set_preference('network.proxy.socks', '127.0.0.1')
firefox_options.set_preference('network.proxy.socks_port', 9050)
firefox_options.set_preference("network.proxy.socks_remote_dns", False)
firefox_options.binary_location = r'C:\Users\username\Desktop\Tor Browser\Browser\firefox.exe'
service = Service('C:\\BrowserDrivers\\geckodriver.exe')
driver = webdriver.Firefox(service=service, options=firefox_options)
driver.get("https://www.tiktok.com/")
References
You can find a couple of relevant detailed discussions in
How to initiate a Tor Browser 9.5 which uses the default Firefox to 68.9.0esr using GeckoDriver and Selenium through Python
How to connect to Tor browser using Python
How to use Tor with Chrome browser through Selenium
BotD detects you because you do not override navigator.webdriver attribute.
I was able to override it with this code:
((JavascriptExecutor)driver).executeScript("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})");
Re-run your code with this line after driver.get("BotD url") and click on
'Start detect' on the BotD page.
It will no longer show that webdriver is detected.
I understand you are looking for a way to make it work before the initial page load.
But here are 2 things to consider:
Webdriver developers want their tool to be detected by browsers.
Gecko driver developers are not going to implement an option to disable navigator.webdriver attribute. (This is the official reply from gecko developer.)

Chrome driver throwing error- Loading of unpacked extension is disabled by administrator

Yesterday my chrome version got updated to 76, I updated my chrome driver for the same- ChromeDriver 76.0.3809.12, I am facing the same error msg. I have used options.setExperimentalOption("useAutomationExtension", false); already, but still getting the same error every time before launching chrome. Please help as it is blocking my batch execution.
With last update of chrome same error was coming but go resolved with :
opts.setExperimentalOption("useAutomationExtension", false);
ChromeOptions opts = new ChromeOptions();
opts.addArguments("--disable-notifications");
opts.addArguments("no-sandbox");
opts.addArguments("--disable-extensions");
opts.setExperimentalOption("useAutomationExtension", false);
//opts.addArguments("start-maximized");
capabilities.setCapability(ChromeOptions.CAPABILITY, opts);
//webdriver = new ChromeDriver(opts);
webdriver = new ChromeDriver(capabilities);
Want to remove this warning pop up so that I can resume execution.
I got it solved by using chrome options instead of capabilities as below:
chrome_options = Options()
chrome_options.add_argument('-disable-extensions')
webdriver = webdriver.Chrome(options=chrome_options)
Have a look at one '-' instead of '--' in the argument. When I used '--disable-extensions' id didn't work. Maybe some side effect. The code is in python, but java variation could work as well.

Hot to suppress EdgeDriver messages from log?

Is it possible to suppress the logs created from selenium edge driver? Specifically these sorts of log entries:
[17:00:32.066] - Listening on http://127.0.0.1:25321/
I've tried similar ways to the Chrome, Firefox, and IE drivers, but none have the desired outcome.
For example
Chrome...
System.setProperty("webdriver.chrome.args", "--disable-logging");
System.setProperty("webdriver.chrome.silentOutput", "true");
System.setProperty("webdriver.chrome.driver", "src\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
Firefox...
System.setProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE, "/dev/null");
System.setProperty("webdriver.gecko.driver", "src\\drivers\\geckodriver.exe");
driver = new FirefoxDriver();
IE...
InternetExplorerDriverService.Builder ieDriverService = new InternetExplorerDriverService.Builder().withSilent(true);
System.setProperty("webdriver.ie.driver", "src\\drivers\\IEDriverServer.exe");
driver = new InternetExplorerDriver(ieDriverService.build());
During test execution to see lesser logs you could simply pass --silent argument to the chromedriver server like this System.setProperty("webdriver.chrome.silentLogging", "true");.
In edgedriver, you could try the answer in this thread. It completely disables the logs in "set-up" time.
For me, I use the SuppressInitialDiagnosticInformation property under EdgeDriverService class. The property is default to false. By setting it to true, the diagnostics outputs can be suppressed. I use it in C# like this:
EdgeDriverService service = EdgeDriverService.CreateDefaultService();
service.SuppressInitialDiagnosticInformation = true;
service.HideCommandPromptWindow = true;
var driver = new EdgeDriver(service);
The usage in chromedriver is the same. You could refer to ChromeDriverService Class and EdgeDriverService Class for more information.

Selenium Grid - Unable to find elements on the 2nd page in IE11

I have some selenium tests that work great in Chrome (locally and remotely) but when I run them remotely from my machine to a Windows 2012 VM they can't find any elements AFTER clicking a button to move to the next web page.
Here is a code snippet:
DesiredCapabilities caps = null;
caps = DesiredCapabilities.internetExplorer();
caps.setBrowserName("internet explorer");
caps.setCapability(InternetExplorerDriver.ENABLE_PERSISTENT_HOVERING, false);
caps.setCapability(InternetExplorerDriver.IE_ENSURE_CLEAN_SESSION, true);
caps.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
caps.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
caps.setJavascriptEnabled(true);
caps.setPlatform(Platform.WIN8);
String nodeURL = "http://0.0.0.0:5555/wd/hub"
driver = new RemoteWebDriver(new URL(nodeURL), caps);
// IE launches correctly, goes the cart page. Calculations are done on the pricing, and we click to move to the login page
driver.findElement(By.id("userName")).sendKeys("test#test.com");
// ^^ NoSuchElementException: Unable to find element with id == userName
So obviously there is a good connection made. Actions are performed and my tests move from the cart page to the login page. I even added a wait.until, hoping that it was a timing issue, but it timed out after 15 seconds. I'm watching the driver on RDP, it moved to the page. During the 15 seconds, I even opened the dev tools and checked to see if the element was there and it was.
What's going on? Thanks!
Preface: As a QA automation engineer, I hate IE.
It turns out that http://company.com was added a trusted site, but not https://company.com. Once I added that, it started working.
Did I mention I hate IE?

PhantomJS slower than ChromeDriver, using Selenium

I'm trying to use PhantomJS 2.0/GhostDriver instead the ChromeDriver, since I have read I could speed up my UI tests.
This is the test code I'm running, as part of a Junit test:
#Override
public void runTestCase() throws Exception {
long startTime = System.currentTimeMillis();
// log in as admin
Login.loginAs("admin", "password");
System.out.println(System.currentTimeMillis() - startTime);
}
The loginAs function fills in the text fields for the username and password, then click on the submit button and finally moves in the home section of the new returned page.
Now, I'm running once a time this simple test using both Phantomjs and ChromeDriver as driver for Selenium in Java (v2.45).
They are initialized as follow:
ChromeDriver
System.setProperty("webdriver.chrome.logfile", workingDirectory + "\\chromedriver.log");
service = new ChromeDriverService.Builder().usingDriverExecutable(new File(workingDirectory + "\\chromedriver.exe")).build();
capabilities = DesiredCapabilities.chrome();
options = new ChromeOptions();
options.addArguments("--allow-file-access-from-files");
options.addArguments("--verbose");
capabilities.setVersion("");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(service, capabilities);
PhantomJS
System.setProperty("phantomjs.binary.path", workingDirectory + "\\phantomjs.exe");
cliArgsCap = new ArrayList<String>();
capabilities = DesiredCapabilities.phantomjs();
cliArgsCap.add("--web-security=false");
cliArgsCap.add("--ssl-protocol=any");
cliArgsCap.add("--ignore-ssl-errors=true");
cliArgsCap.add("--webdriver-loglevel=INFO");
cliArgsCap.add("--load-images=false");
capabilities.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true);
capabilities.setCapability(CapabilityType.TAKES_SCREENSHOT, true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, cliArgsCap);
driver = new PhantomJSDriver(capabilities);
I'm running my test on a 64bit Windows 7 machine. So, having a look the time took by the test, I always note that ChromeDriver is faster than PhantomJS. Always. For instance, if the test with ChromeDriver takes about 3-4 seconds, the same with PhantomJS takes about 5-6 seconds.
Has anyone experienced with this issue? Or could anyone give me any reason for that? Am I setting something wrong?
Furthermore, if you need more details, let me know.
I have found that this setting uses a lot of memory that seems to keep growing:
cliArgsCap.add("--load-images=false");
But when I use this setting the memory usage is stable:
cliArgsCap.add("--load-images=true");
"PhantomJS is a headless WebKit scriptable with a JavaScript API" as it's explained on the main page of the project.
Google split from WebKit to create Blink to use it in Chrome.
What are the main differences between them - unfortunately I'm not the expert here.
I run one of my really long scenarios both on Chrome and PhantomJS and to my surprise the difference was pretty significant:
PhantomJS - 583.251 s
Chrome - 448.384 s
Using PhantomJS doesn't bring performance benefits in my case but running tests headless does. I can use machine without graphical desktop and save computing power for some additional threads.
The slowest aspect of a web page is the downloading of html, JavaScript, css, images, etc and making AJAX request.
To anybody who says Headless is faster, how can headless address any of these?

Categories