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.
PhantomJS is a headless browser that can be used with the Selenium web automation module. Unlike the FirefoxDriver or ChromeDriver, the browser stays totally invisible during the process. It behaves just like the other browsers.
"Selenium support for PhantomJS has been deprecated, please use headless versions of Chrome or Firefox instead" #48.
PhantomJS is a headless Webkit, which has a number of uses. In this example, we'll be using it, in conjunction with Selenium WebDriver, for conducting basic system tests directly from the command line. Since PhantomJS eliminates the need for a graphical browser, tests run much faster.
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);
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With