ChromeDriver sitting on Data:, when launching selenium/cucumber test - java

I have hit a brick wall here; I am completely unable to run any selenium tests on Chrome, as every time I launch it, the chrome browser will open and hang for 600 seconds, with Data:, in the address bar. I have tried every solution under the sun found so far on stack overflow.
Verified the versions between ChromeDriver and Chrome browser - yes they match.
Uninstalled/reinstalled chrome several times, and also verified the versions match.
The interesting thing is that running the tests on Microsoft Edge work fine, which leads me to believe there could be an issue with Chrome/Chromedriver not having the correct permissions? The machine the tests are running on is managed by my company. Any and all help would be greatly appreciated here.
Thanks :)

I think your issue is in the configuration of the WebDriver object.
If you use Maven, there is a library which helps configuring the webdrivers. Or if you aren't, then you can download the .jar file and add it to your build path.
https://github.com/bonigarcia/webdrivermanager
With this, you don't need to download the driver file itself and set the system property for it's value.
Here is a quick example for creating the ChromeDriver object:
WebDriverManager.chromedriver().setup();
WebDriver driver = new ChromeDriver();
The same thing on Edge:
WebDriverManager.edgedriver().setup();
WebDriver driver = new EdgeDriver();
Try this at your WebDriver configuration and maybe it can help!
Happy coding! :)

I have solved this problem - the administrators of the computers I was using had not given access to Chrome's developer tools. After getting access, the problem had gone away. Hope this helps anyone else who encounters this problem :)

Related

Possible issue with Chromedriver 78, Selenium can not find web element of PDF opened in Chrome

Until my google Chrome wasn't updated to version 78 my code worked fine. I also updated the chromedriver to version 78.0.3904.70. So I am not able anymore to find WebElement with id='plugin' using Selenium WebDriver and Java:
<html>
<div id="content">
<embed id="plugin" type="application/x-google-chrome-pdf" src="http://??????????/offer_printed.php?printable=yes&reanudar=&>
</div>
</html>
Other than that part my tests are working fine. I never had a similar issue before. I also tried to find WebElement id='content' but I am receiving the same error.
WebDriverWait wait = new WebDriverWait (driver, 90);
WebElement scrollvalid = wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("plugin")));
scrollvalid.sendKeys(Keys.PAGE_DOWN); scrollvalid.sendKeys(Keys.PAGE_DOWN);
My automation script should find the PDF element and scroll the page down. Instead, I am receiving this error:
org.openqa.selenium.TimeoutException: Timed out after 90 seconds waiting for visibility of element located by By.id: plugin
Is anybody facing a similar issue? Thanks in advance.
I've run into the same issue.
Apparently Chrome automatically updates itself. Yesterday (Oct 29 '19) My ChromeDriver started complaining that it was not compatible with Chrome 78. I updated the driver to the 78 version. I started to get random org.openqa.selenium.NoSuchElementException exceptions when trying to find elements that I confirmed were there. The findElement[s] also work when I used breakpoints. I also tried implicit waits, with only limited success.
I tried zsbappa's ChromeOption solution but no joy.
Google makes it hard to get old versions of Chrome, but I found version 76 at https://www.neowin.net/news/google-chrome-76-offline-installer/. Beware, the online installer installs the latest version. I reverted to the driver for 76 and all is good. All my Selenium tests are working again.
My conclusion is that the Chrome 78 and it's associated driver has a race condition where Selenium attempts to interrogate the web page before it's complete.
We have faced a similar issue with Chrome 78.0.3904.7, Chromedriver 77/78, Python Selenium 3.141.0.
In our automated Python Selenium tests, we've seen multiple failures where it appears that clicks on elements have not occurred. Even stranger, it appears that the element has become active (as if it were about to be clicked) but the the actual click event never occurred. As a result, page switches etc do not occur resulting in various downstream failures.
By a process of trail and error, we found that using the standard .click() function is now not reliable:
webdriver_element.click()
But using Action Chains does appears to be reliable:
ActionChains(context.browser).click(webdriver_element).perform()
It's not clear why this is the case. The failures began as soon as we upgraded to Chrome 78.0.3904.7. We're using Chromedriver 77.0.3865.90 but the same tests pass reliably on Chrome 77.x versions therefore it appears something is wrong or has changed in Chrome 78.
By adding the following argument I have solved my problem.
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-gpu");
options.addArguments("--disable-extensions");
options.setExperimentalOption("useAutomationExtension", false);
options.addArguments("--window-size=1920,1080");
options.merge(seleniumCapabilities);
driver = new ChromeDriver(options);
I have faced the same issue when trying to access a tab inside an iframe , it used to work fine on version 76. Now that has updated itself to 78, it's failing.
Have tried waits , implicit waits , sleep , locate the elements using xpath, CSS, id , switch context , scroll until view , etc.., with no luck.
I'm using windows 10 , 1809. I don't know if this is happening in other OS.
Here is the question I raised :
Problem using chromedriver 78.0.3904.70 locators
I confirmed yesterday that this issue appears to manifest itself only when an element is contained in an iframe. In those cases, the iframe is located fine. However, attempting to locate a web element using the driver or web driver wait objects will result in a NoSuchElement or TimeoutException respectively.
I provided the chromedriver team a verbose chrome driver log and they are working on it.
UPDATE:
From chromedriver issue 3223
The logs show that the final executionContextCreated for the frame doesn't complete until after the FindElement returns null.
Starting in version 77, ChromeDriver stopped waiting for all frames to load before continuing navigation. Unfortunately, that change prevented a wait for the current frame to load. 3164 will all a wait for the current frame to load; this should prevent FindElement from searching until after the frame has Stopped loading and the executionContext is created.
Basically, this bug was introduced in v.77. Many of us just noticed this problem because we upgraded from v.76 to .v78. Word is that they are targeting a fix for .v80 (not v. 79). As a workaround, I am using Thread.sleep between the time I switch to the iframe and when I attempt to locate the component. This workaround works fine. In fact, you can verify this on your own by simply running your application in DEBUG mode. When you pause execution (by using a breakpoint), you'll notice that your original code (without the sleep) works fine.
For example: You can try using this keywords!.
1. implicit_wait=10
2. Sleep 10
It turned out to be a problem with the Google Chrome, not chromedriver: https://bugs.chromium.org/p/chromedriver/issues/detail?id=3211
I had the same issue.
After auto-updating Chrome with version 78.0, my automated test scripts were failing. So I updated chromedriver to the 78 version, but driver was still not able to find any web element. After that I tried with multiple versions of chromedriver and finally my issue is resolved with chromedriver version 2.44.
This version can be found at https://chromedriver.storage.googleapis.com/index.html?path=2.44/
You can Nuget package manager, delete Chrome drive and search for chrome, download the new version selenium.web.driver.ChromeDriver >> for jsaKamoto
there you find chrome version 78.

Headless Chrome - getting blank page source

I'm trying to load a website with Chrome browser in headless mode using Selenium web driver. I face an issue with some specific websites. The page is loading, in the first 2-3 seconds it shows a page with "please enable javascript..." and after 3 seconds, page source goes blank.
I'm using Selenium and especially Chrome for long time and I am familiar with the platform. For the purpose of this case, I'm using Chrome Version 73.0.3683.86 , ChromeDriver 2.46.628411 (which is compatible according to Which ChromeDriver version is compatible with which Chrome Browser version?) on a Mac OS. selenium java version is latest - 3.141.59
I suspect that headless Chrome cannot handle specific content-type such as "svg" and any other GUI related HTTP response.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver(chromeOptions);
driver.get("https://identity.tescobank.com/login");
Thread.sleep(3000);
System.out.println(driver.getPageSource());
driver.quit();
Expected result is to have the page source same as it is showing in non-headless mode.
Headless Chrome should be able to handle everything the normal Chrome can do:
It brings all modern web platform features provided by Chromium and the Blink rendering engine to the command line.
(see https://developers.google.com/web/updates/2017/04/headless-chrome)
Since only the login page of a bank causes you trouble, my guess is that the security of the page detects an anomaly and decides not to serve you.
One way they can do that is by looking at the User Agent string which contains HeadlessChrome.
That said, unless you're writing integration tests for the bank, your behavior is at least suspicious. If you have a valid and legal concern, clear it with the bank first. They might take actions against you, otherwise. Blocking your IP address (which could affect many people) or asking the police to have a word with you.
I was facing similar issue in my script, after login. Somehow refreshing the page resolved the issue.
driver.navigate().refresh();

How to enable flash in Selenium with headless chrome

I'm trying to automate some interactions with our flash app as part of our CI process. I'm running into troubles with enabling flash when running chrome headlessly (via xvfb-run) with Selenium Standalone Server. I've done a lot of searching, but thus far haven't come up with anything that works.
I'm currently using this, but am open to switching to different versions if there's a known working config somewhere...
Selenium Standalone Server 3.11
Chromedriver 2.33
Chrome 65.0.3325.181
Java 8
When I first got this started I would get a warning on the page saying I needed to enable Adobe Flash Player. I got "past" that message by using the following from https://sqa.stackexchange.com/questions/30312/enable-flash-player-on-chrome-62-while-running-selenium-test:
ChromeOptions options = new ChromeOptions();
options.addArguments("headless");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.plugins", 1);
prefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
// Enable Flash for this site
prefs.put("PluginsAllowedForUrls", "ourapp.com");
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
driver.get("ourapp.com");
When loading our app, the page now gives a slightly different message which I haven't been able to get past. Is there a way to get around this, or is there any other way to enable Flash by default?
Restart Chrome to enable Adobe Flash Player
Thanks in advance for the help!
Thanks to a coworker for pointing out this post indicating that plugins don't work in headless chrome. https://groups.google.com/a/chromium.org/forum/#!searchin/headless-dev/flash%7Csort:date/headless-dev/mC0REfsA7vo/rKAZdRrCCQAJ
Fortunately in my case I was already using xvfb as a virtual display, so removing the "headless" argument from my ChromeOptions was all I needed to get everything running.
EDIT*
While true that I did not need to run in headless mode while using xvfb, I ended up finding that the real 'solution' (more of a workaround) to my problem was to upload a custom chrome profile into my docker image. Doing so allowed me to set all the preferences I needed, and none of the code posted in the original post is required. Would much prefer to achieve this programatically, but this at least gets me what I need for now. Figured I'd post in case someone else runs into this in the future..

Chrome WebDriver doesn't select from dropdown

I have got the following code working on Firefox, but not on Chrome.
Select selectSize = new Select(dropDownListBox);
selectSize.selectByIndex(1);
I've tried using explicit wait and Thread.sleep(), but couldn't make it work.
When I debug the code, I found out that it actually grabs the value, but doesn't update the UI.
When I use System.out.println(selectSize.getFirstSelectedOption().getText()); it actually prints the size.
I've also tried running this code on iPhone and iPad emulators and it worked on there as well. I feel like this only doesn't work with Chrome Driver.
Has anyone had this issue before or do you have any suggestions?
Update: I'm using Selenium 2.41.0 and Chrome WebDriver 2.9.
Thanks in advance

How to close or disable base authentication popup in WebDriver(FirefoxDriver) test

I'm using WebDriver for testing my application, but some pages are trying to get resources from another server, which requires authentication. I don't need that resources for my test and I don't have credentials as far.
When popup appears, it stops test run.
I tried to close popup using webDriver.switchTo().alert().dismiss(); but obviously it's not alert.
I tried also to disable popup using firefox profile:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("capability.policy.policynames", "strict") ;
profile.setPreference("capability.policy.strict.sites", "http://localhost:9000") ;
profile.setPreference("capability.policy.strict.Window.alert", "noAccess") ;
profile.setPreference("capability.policy.strict.Window.confirm", "noAccess") ;
profile.setPreference("capability.policy.strict.Window.prompt", "noAccess") ;
FirefoxDriver driver = new FirefoxDriver(profile);
but it didn't help.
Thanks in advance.
I dont think web driver was designed with the above intent in mind and I dont see any such api being provided in the near future too.. They would want to test to behave exactly how a human would see the page.
Having said that you have control over the site that you are running the test against. cant you block these resources yourself probably be using some configuration setting that doesnt load the resource when the flag in the configuration is set to true.
The setting might be something like IsSeleniumInstance.
Hope this helps.
This is an open issue for Selenium: http://code.google.com/p/selenium/issues/detail?id=34
There is a fix for Firefox, but I don't believe it is included in any of the current releases. The fix still needs to be implemented for other supported browsers.

Categories

Resources