Chrome closing after long Selenium execution - java

My goal is to get comments data from a website. Feedback is in different div region/ class.
I am able to get data until i reach certain point but after more then 20 minute of execution, comments loading slowly and chrome closing itself. Test fails with unable to find element. I am using below Chrome options and new selenium 4 feature devtools to block this issue.
using bonigarcia along with selenium 4.
Can anyone advice me anything to fasten this execution?
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--blink-settings=imagesEnabled=false");
//options.addArguments("--headless");
options.addArguments("--disable-extensions");
options.addArguments("--no-sandbox");
options.addArguments("-disable-cache");
//options.addArguments("--window-size=1920,1080");
//options.addArguments("--disable-dev-shm-usage");
options.addArguments("--disable-javascript");
options.addArguments("--lang=en");
options.addArguments("--start-maximized");
options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
options.setExperimentalOption("useAutomationExtension", false);
driver = new ChromeDriver(options);
DevTools devTools = ((ChromeDriver)driver).getDevTools();
devTools.createSession();
devTools.send(Network.enable(Optional.empty(), Optional.empty(), Optional.of(100000000)));
devTools.send(Network.setCacheDisabled(true));

No fix for this, loading more items increases the memory of the chrome that is why you are facing an issue.

Related

How to run Webdriver headless with Chrome profiles

I have been use Chrome profiles to login a website it was success...! But want to browser not showing up so I added options.addArguments("user-data-dir="+myProfilesPath); after then it not working! Plzz tell me why headless argument not working with profiles? And How do I solve that problem?
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
WebDriver driver = new ChromeDriver(options);
driver.get("https://www.google.com/");

Selenium ChromeDriver script through Task Scheduler while logged out

To preface, I cannot run in --headless mode because I unfortunately need to get a file to download, and using ChromeDriver without --headless is the only way I can get it to work. The script runs fine manually, and also runs fine when scheduled and logged in, but it failed when scheduled and the screen was locked/user logged out.
I ideally want this to be able to run while logged out but still have access to the default ChromeDriver behavior that exists when I'm logged in/unlocked. I have a bad feeling this isn't possible because it seems as though the non-headless version depends on a graphics input, but I'm hoping I'm wrong. Again, the file download is the main constraint here, otherwise I would just use HTMLUnitDriver.
Here is my driver configuration for reference:
//browser prefs
HashMap<String, Object> preferences = new HashMap<>();
preferences.put("profile.default_content_settings.popups", 0);
preferences.put("download.default_directory", downloadPath);
//browser options config
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", preferences);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
//add capabilities to options
options.merge(cap);
WebDriver driver = new ChromeDriver(options);
I'm using the newest version of chromedriver.exe.
I think, that the point is, that you try to run test when you not loggged in on windows.
Maybe you should create server for automatic tests. Stable and without costs will be server on linux. You can launch without x-wing -
more in (this if for firefox, but you can just change driver to chromedriver and all will works fine) Is it possible to run selenium (Firefox) web driver without a GUI?

how to start chrome --disable-impl-side-painting in selenium

I'm having problems with my Selenium tests. Sometimes, I get "no such session" error in my Eclipse when I run my Selenium Test in a external server Jenkins.
I've read that the solution is starting chrome with option --disable-impl-side-painting.
Do you know how could I disable that option from my java Selenium test??
Thanks so much!!!
You could try
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-impl-side-painting");
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver driver = new ChromeDriver(capabilities);
Hope this helps

Selenium - chrome Driver fail to start in background (without a start-up window)

I am using Selenium and trying to initialize the Chrome driver to start without a start up window.
ChromeOptions options= new ChromeOptions();
options.addArguments("--no-startup-window");
//I tried this line also: options.addArguments("--silent-launch");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(Capabilities);
I am getting the following exception:
Unknown error: Chrome failed to start: exited normally
Can anybody help me?
You need to download the binary first from selenium website, download binary according to your specifications:-
http://chromedriver.storage.googleapis.com/index.html?path=2.19/
Now set below code so selenium script will know the path of your binary
System.setProperty("webdriver.chrome.driver","./src\\lib\\chromedriver.exe");
So the code should be like this:-
System.setProperty("webdriver.chrome.driver","./src\\lib\\chromedriver.exe");
ChromeOptions options= new ChromeOptions();
options.addArguments("--no-startup-window");
//I tried this line also: options.addArguments("--silent-launch");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
Hope it will help you :)
I think the flag you are looking for is --headless
This feature has just been implemented in chrome 57
--no-startup-window is used for hosting background apps, see this page and as mentioned in the other answers doesn't launch a window which is why the webdriver can't talk to it.
--headless does launch a window, but doesn't make it visible.
I am using Selenium and trying to initialize the Chrome driver to start without a start up window.
According to Selenium GitHub (Strange error, chromedriver with --no-startup-window), Selenium requires JavaScript and Chrome window to work:
Much like --disable-javascript, the chromedriver will not work if you use --no-startup-window.
It needs to launch a window to establish the connection with the AutomationProxy.

ChromeDriver - Disable developer mode extensions pop up on Selenium WebDriver automation

I'm having the following issue:
When I'm running my automation tests, I keep getting the following alert "Disable Developer Mode Extension" in Chrome.
Is there a way to remove/disable this?. It is a blocker for me as it is making me fail some tests.
Thanks in advance
Did you try disabling the developer extensions with command line param?
Try with the following Selenium WebDriver java code:
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
driver = new ChromeDriver(options);
I cannot disable extensions because I'm developing & testing one.
What I'm doing to dismiss this popup is the following:
I load chrome with my extension using Selenium.
I then immediately create a new window (via the SendKeys(Control-N) method). This predictably brings up the "Disable Developer Mode Extensions" popup after 3 seconds in the new window.
I can't tell programmatically when it pops up (doesn't show in screenshots) so instead I simply wait 4 seconds.
Then I close the tab via driver.Close(); (which also closes this new window). Chrome takes that as "cancel", dismissing the popup, leaving the original window and tab.
I find this necessary because the popup interferes with normal selenium browser interaction, like SendKeys, which I'm using to switch tabs and windows.
As of Chromedriver v2.33, the correct way to avoid this message is to pass load-extension to the excludeSwitches argument of the chromeOptions object. The following Java code should do the trick, although I haven't tested it, as I am running Python:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Collections.singletonList("load-extension"));
As others have pointed out, the culprit is probably the Chrome Automation Extension, which is loaded automatically by Chromedriver when it launches Chrome.
Chromedriver v2.33 introduced the new switch to prevent the extensions from being loaded:
Updates to excludeSwitches capability that now allows to exclude --load-extension switch.
I suspect that this solution does not require you to disable all extensions. You should still be able to manually load others.
This has been automatically fixed with a combination of ChromeDriver.exe V2.23 + Chrome 53.0.
To understand which chrome version will work with which driver, we can use the following well detailed doc: https://sites.google.com/a/chromium.org/chromedriver/downloads
Enjoy Automated Testing!!
I worked around this issue by using AutoIT.
First, you'll need to create the script.
closechromewarning.au3:
WinWaitActive("[CLASS:Chrome_WidgetWin_1]")
Send("{ESC}")
The script needs to be compiled to a .exe, then place the .exe in the path so it can be run.
Function that closes the warning, using c# syntax:
public void CloseChromeDialog()
{
System.Threading.Thread.Sleep(5000);
Process.Start(#".\closechromewarning.exe");
}
Sleep(4000) did work, but I upped it to Sleep(5000) just to be sure.
Calling CloseChromeDialog():
if(browser == chrome) //pseudo code
CloseChromeDialog();
resolved in chrome 54 and chromedriver 2.25
I too faced this problem. The solution is, if you are using maven then just add:
-Dchrome.switches=--disable-extensions
It will disable all the extensions and you will not face this problem.
I am using selenium Webdriver 2.53 and chrome version 56.0.2924.87 and the chrome driver.exe which I am using is 2.27. with this combination it is working with the
System.setProperty("webdriver.chrome.driver", "./utilities/chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
DesiredCapabilities caps = new DesiredCapabilities().chrome();
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);
Try to add setProperty above ChromeDriver instance
System.setProperty("webdriver.chrome.driver","C:/[PATH]/chromedriver.exe");
driver = new ChromeDriver(capabilities);
pywinauto works
import pywinauto
window_title = "Disable Developer Mode Extensions"
app = pywinauto.Application().connect(name_re=window_title)
win_ext = app.window(name=window_title)
win_ext.close()
This is because one of your extensions is running in developer mode. Go through your extension list and disable extensions one-by-one until you find the culprit(s).

Categories