14

I am trying to use PhantomJS with Selenium Webdriver and got success but for a specific website I see that it does not navigate to the URL. I have tried it with both Python and C#.
Python Code:

dcap = dict(webdriver.DesiredCapabilities.PHANTOMJS)
dcap["phantomjs.page.settings.userAgent"] = ("Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36")
service_args = ['--load-images=false', '--proxy-type=None']
driver = webdriver.PhantomJS(executable_path="C:\\phantomjs.exe", service_args=service_args, desired_capabilities=dcap)
driver.get("https://satoshimines.com")
print driver.current_url

The output of this code snippet is: about:blank
Whereas it works fine for any other website.

Same code with C#:

IWebDriver driver = new PhantomJSDriver();
driver.Navigate().GoToUrl("https://satoshimines.com");
Console.WriteLine(driver.Url);

The output of the C# program is also same.

I am stuck here and need help.

Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
  • What version of the driver are you using? What about other drivers? Are you able to successfully navigate to pages using the ChromeDriver for instance? Is this reproducible on another machine? – Arran Dec 20 '13 at 13:50
  • Hi @Arran, I am using Selenium Webdriver 2.39 and PhantomJS 1.9. Yes, I have already a working program for the same URL using Firefox driver. – Vikas Ojha Dec 20 '13 at 14:01
  • I think I have found the solution. It was a SSL handshake problem. By passing '--ignore-ssl-errors=true' in service_args to phantomjs solves the issue. – Vikas Ojha Dec 20 '13 at 15:36

5 Answers5

21

Following is a complete code solution for c# -

PhantomJSDriverService service = PhantomJSDriverService.CreateDefaultService();
service.IgnoreSslErrors = true;
service.LoadImages = false;
service.ProxyType = "none";

driver = new PhantomJSDriver(service);
Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
9

For me, the solution was as follows:

var service = PhantomJSDriverService.CreateDefaultService();
service.SslProtocol = "tlsv1"; //"any" also works

driver = new PhantomJSDriver(service);

I have no idea why the default sslv3 will not work. If you are sure the SSL certificates are valid, it is quite recommended not to ignore errors to protect against malicious certificates.

Update: For a very good explanation why SslProtocol should now be set to tlsv1 instead of the default sslv3, please take a look at the excellent cross link provided below by @Artjom B.

Community
  • 1
  • 1
Erwin Mayer
  • 18,076
  • 9
  • 88
  • 126
7

It seems I have found a solution to this. The problem was an SSL handshake problem. By passing
'--ignore-ssl-errors=true' as a service_args to phantomjs solves the issue.

Thanks

Vikas Ojha
  • 6,742
  • 6
  • 22
  • 35
  • Where exactly do you add this to the service_args? because i am stuck with the same problem now – Henk Jansen Jan 10 '14 at 12:13
  • @HenkJansen, Tell me which programming language are you using? I will post the code accordingly. – Vikas Ojha Jan 10 '14 at 13:12
  • C# sorry. i thought i added it. – Henk Jansen Jan 10 '14 at 13:19
  • @HenkJansen, I have just posted another answer. Hope that helps. – Vikas Ojha Jan 10 '14 at 13:35
  • 1
    I'm using Splinter (which uses Selenium underneath) and doing: `b = Browser('phantomjs', service_args=['--ignore-ssl-errors=true'])` solves the 'about:blank' issue for me as well. Sadly, it is not documented on their site. – kenshin23 Aug 08 '14 at 14:09
  • 1
    For python, you would add that flag in a similar way: `driver = webdriver.PhantomJS(service_args=['--ignore-ssl-errors=true', '--ssl-protocol=tlsv1'])` – Steve Oct 17 '14 at 15:05
4

this worked for me:

DesiredCapabilities capabilities = DesiredCapabilities.phantomjs();
capabilities.setJavascriptEnabled(true);
capabilities.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, new String[] {"--web-security=no", "--ignore-ssl-errors=yes", "--ssl-protocol=tlsv1"});
driver = new PhantomJSDriver(capabilities);
ramigg
  • 1,287
  • 1
  • 15
  • 16
1

Ran into this issue on an application quite abruptly after running phantomjs 1.9.7 for months without incident. The solution? Update phantomjs to 2.0.0.

mdpatrick
  • 1,082
  • 9
  • 12