FuckTheWorld / chromedriver

Automatically exported from code.google.com/p/chromedriver
0 stars 0 forks source link

Unable to open a PDF file in chrome since upgrading to v 42.0.2311.90 #1081

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Issue Description:
Since chrome browser upgraded from v 41.0.2272.118 to v 42.0.2311.90, unable to 
open a PDF file inside the chrome browser started by chrome driver. Tried with 
chrome driver v2.14 and v2.15, and in both cases when opening a PDF file it 
gets downloaded whereas earlier it used open inside browser using chrome pdf 
viewer plugin. 

Steps to reproduce (if relevant, you MUST provide a simplified html page or
link to public site):
Powershell
1. Add-Type -Path ".\Selenium.WebDriverBackedSelenium.dll"
Add-Type -Path ".\ThoughtWorks.Selenium.Core.dll"
Add-Type -Path ".\WebDriver.dll"
Add-Type -Path ".\WebDriver.Support.dll"

2.$chromeOptions = New-Object OpenQA.Selenium.Chrome.ChromeOptions
$chromeOptions.AddExcludedArgument("ignore-certifcate-errors")
$chromeOptions.AddArgument("test-type")
$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver($chromeOptions)

3. Now try opening a pdf file inside the browser

Actual Result:
PDF file gets downloaded

Expected Result:
PDF file should open within the browser tab

-----Other helpful tips:
Used to work with Chrome browser v 41.0.2272.118
However when opening an instance of chrome browser without 
Selenium/chromewebdriver PDF file opens inside the tab in the browser.  

Original issue reported on code.google.com by vidhes...@gmail.com on 16 Apr 2015 at 9:30

GoogleCodeExporter commented 9 years ago
Issue is reproducible with latest chrome browser version 42.0.2311.90
And chrome driver v2.14 & v2.15

Sample HTML:-

<html>
<body>
<a title="PDF doc" target="_blank" 
href="http://ga.berkeley.edu/wp-content/uploads/2015/02/pdf-sample.pdf">Sample 
PDF document</a>
</body>
</html>

Code:-
System.setProperty("webdriver.chrome.driver", 
"/usr/local/google/home/gmanikpure/Downloads/chromedriver2.15");
WebDriver driver = new ChromeDriver();
driver.get("file:///usr/local/google/home/gmanikpure/Issue1081.html");
driver.findElement(By.xpath("html/body/a")).click();

Original comment by gmanikp...@chromium.org on 16 Apr 2015 at 7:13

GoogleCodeExporter commented 9 years ago
Last Good build version - 42.0.2274.0
First bad build version - 42.0.2275.0 

Original comment by gmanikp...@chromium.org on 16 Apr 2015 at 11:51

GoogleCodeExporter commented 9 years ago
Can someone please post a solution for this. 
I am using chrome Version 42.0.2311.90 m and the PDF gets downloaded instead of 
opening it.

Original comment by pallasra...@gmail.com on 23 Apr 2015 at 6:45

GoogleCodeExporter commented 9 years ago
Hello I have the same problem! 
According to me chromedriver is not using chrome embedded PDF viewer, despite 
it is enabled (see chrome://plugins). 
Please note if you disable PDF viewer manually and try to open pdf it will be 
downloaded. My workaround for that bug is to install another pdf viewer. Now my 
tests are using this viewer to open pdf in new tab instead of downloading it. 
The only problem I have now is to unblock this plugin. Currently pdf are loaded 
but not displayed. Does anyone knows how to set "Always allow to run" flag for 
plugin using java webdriver code? I have tried to use 
--always-authorize-plugins or --always-authorize-plugins=true but it didn't 
work.

Original comment by Wojciech...@gmail.com on 27 Apr 2015 at 8:53

GoogleCodeExporter commented 9 years ago
Have this same issue. We were recently forced to upgrade to the latest 
chromedriver version as older versions failed to load URLs when we were running 
our Selenium tests. Now our PDFs that are supposed to open in new tabs are 
automatically downloading and this is not acceptable behavior.

Original comment by abullo...@gmail.com on 27 Apr 2015 at 5:36

GoogleCodeExporter commented 9 years ago
At some point between M41 and M42, the behavior of the --test-type switch was 
changed so that PDFs are downloaded instead of displayed. As a temporary 
workaround, you can disable this switch. Here's how to do that in Python:

>>> from selenium import webdriver
>>> options = webdriver.ChromeOptions()
>>> options.add_experimental_option('excludeSwitches', ['test-type'])
>>> driver = webdriver.Chrome(chrome_options=options)

One side-effect of removing this switch is that you'll get infobar warnings 
about unsupported command-line flags (similar to the one in issue 799), but 
these warnings should not affect the behavior of the browser.

Original comment by samu...@chromium.org on 28 Apr 2015 at 6:46

GoogleCodeExporter commented 9 years ago
It helped!
Thank you!
Solution in Java is as follows:
options.setExperimentalOption("excludeSwitches",Arrays.asList("test-type"));

Original comment by Wojciech...@gmail.com on 29 Apr 2015 at 1:01

GoogleCodeExporter commented 9 years ago
c#

            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.AddExcludedArgument("test-type");
            var browser = new ChromeDriver(chromeOptions);  

Original comment by yuriy.ya...@gmail.com on 29 Apr 2015 at 8:21

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is due to the OOP PDF viewer, which was enabled by default in 
https://codereview.chromium.org/850633002

So a better workaround is to use --disable-out-of-process-pdf. This will avoid 
those annoying infobar warnings:

>>> from selenium import webdriver
>>> options = webdriver.ChromeOptions()
>>> options.add_argument('--disable-out-of-process-pdf')
>>> driver = webdriver.Chrome(chrome_options=options)

Original comment by samu...@chromium.org on 29 Apr 2015 at 8:30

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Thank you! The first solution solved our problem. The 2nd solution didn't 
change the behavior of our tests.

Original comment by abullo...@gmail.com on 30 Apr 2015 at 4:09

GoogleCodeExporter commented 9 years ago
I am using Yuri.ya's solution and it is working until a few minutes into the 
test. When the pdf viewer pops up, it becomes stuck at "Loading preview..." and 
chrome then becomes unresponsive. 

     ChromeOptions options = new ChromeOptions();
     options.AddExcludedArgument("test-type");
     options.AddArgument("-incognito");
     options.AddArgument("-start-maximized");
     driver= new ChromeDriver(driverService, options);

The issue occurs after it has loaded about 10 - 15 pdf's to print, and then 
chrome becomes unresponsive. Any thoughts? 

Original comment by ben.dans...@gmail.com on 30 Apr 2015 at 7:57

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
This is also a problem in java. I have tried all the suggestion shown and none 
worked. Does anyone have a solution?  

Original comment by kcqc...@gmail.com on 1 May 2015 at 6:20

GoogleCodeExporter commented 9 years ago
#7 Worked for me in Java. Here is the code I used:

WebDriver driver = null;
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(desiredCapabilities);

Original comment by abullo...@gmail.com on 1 May 2015 at 6:30

GoogleCodeExporter commented 9 years ago
Your code worked for me.

import java.util.Arrays;
ChromeOptions options = new ChromeOptions();                        
DesiredCapabilities caps = DesiredCapabilities.chrome();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
caps.setCapability(ChromeOptions.CAPABILITY, options);              
driver = new ChromeDriver(options); 

One additional question were you able to turn off the certificate banner ("You 
are using an unsupported command-line flag: --ignore-certificate-errors. 
Stability and security will suffer.") which appear at the top of the browser? 

Thank you

Original comment by kcqc...@gmail.com on 1 May 2015 at 8:35

GoogleCodeExporter commented 9 years ago
@ben.dansie87, your issue is different than the original issue.
Can you please report a new bug ? And please provide a reproducible test page 
and test code

Original comment by gmanikp...@chromium.org on 1 May 2015 at 9:06

GoogleCodeExporter commented 9 years ago
No, I was not able to get rid of the certificate banner. Comment #10's solution 
did nothing for our project.  Glad I was able to help!

Original comment by abullo...@gmail.com on 1 May 2015 at 9:06

GoogleCodeExporter commented 9 years ago
No problem. I got it to work by adding "ignore-certificate-errors" to the array 
list.

options.setExperimentalOption("excludeSwitches", 
Arrays.asList("test-type","ignore-certificate-errors"));

Once again Thank you

Original comment by kcqc...@gmail.com on 1 May 2015 at 9:17

GoogleCodeExporter commented 9 years ago
Nice, I will have to give that a shot. It's just an annoyance for us and not 
affecting our tests but if we can get rid of it, all the better.

You're welcome and thank you!

Original comment by abullo...@gmail.com on 1 May 2015 at 9:19

GoogleCodeExporter commented 9 years ago
Here's the equivalent workaround for nightwatchjs, if anyone is using that 
javascript testing framework:

      "desiredCapabilities": {
        "chromeOptions": {
          "excludeSwitches": [ "test-type" ]
        }
      }

Joel

Original comment by j...@airspringsoftware.com on 5 May 2015 at 4:22

GoogleCodeExporter commented 9 years ago
@gmanikp, the issue I mentioned seems to be resolved in Chrome 43. The beta 
version has fixed my issue. 

Original comment by ben.dans...@gmail.com on 7 May 2015 at 3:44

GoogleCodeExporter commented 9 years ago
@ben.dansie87, Thanks for verifying the issue mentioned in #13!

Original comment by gmanikp...@chromium.org on 8 May 2015 at 7:11

GoogleCodeExporter commented 9 years ago
Hey..In Chrome 43, still we have to exclude switch test-type do make pdf render 
in browser. Because once I exclude test-type switch I am facing a new problem. 
My application opens PDF in new tab and while removing this switch selenium api 
is not able to close the browser.

Original comment by gupta.ji...@gmail.com on 12 May 2015 at 11:01

GoogleCodeExporter commented 9 years ago
Hey , after applying the changes PDF is opening in new tab instead of as a POP 
up, Is there any new settings need to be done to open it as a pop up.

Original comment by varunmit...@gmail.com on 13 May 2015 at 2:41

GoogleCodeExporter commented 9 years ago
after making "$chromeOptions.AddArgument("test-type")" change, i am getting 
pop-up blocker issue for chrome. Solution please

Original comment by sapati...@gmail.com on 15 May 2015 at 10:29

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("excludeSwitches", 
Arrays.asList("test-type","ignore-certificate-errors"));

this code worked for me
chrome version
Version 43.0.2357.65 m

Thanks alot

Original comment by sweta.de...@gmail.com on 24 May 2015 at 2:06

GoogleCodeExporter commented 9 years ago
C# for me it works fine:

                DesiredCapabilities capabilities = DesiredCapabilities.Chrome();
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.AddExcludedArgument("test-type");
                chromeOptions.AddExcludedArgument("ignore-certificate-errors");
                capabilities = chromeOptions.ToCapabilities() as DesiredCapabilities;

Original comment by tomaszwi...@gmail.com on 15 Jun 2015 at 12:31

GoogleCodeExporter commented 9 years ago
#30 Would you clarify the last line? I am not sure what to do with the modified 
capabilities?

Original comment by ronald.k...@gmail.com on 26 Jun 2015 at 4:27

GoogleCodeExporter commented 9 years ago
Hi I was struggling with this issue for a pro longed periods of time finally I 
have solve this issue by the below mentioned code...

Jave Code..

DesiredCapabilities caps = DesiredCapabilities.chrome();
options.setExperimentalOption("excludeSwitches", Arrays.asList("test-type"));
options.setExperimentalOption("excludeSwitches", 
Arrays.asList("testtype","ignore-certificate-errors"));
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(options);

Original comment by sumit16...@gmail.com on 15 Jul 2015 at 11:21