Selenium Webdriver + PhantomJS remains at about:bl

2019-01-12 05:40发布

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.

5条回答
做自己的国王
2楼-- · 2019-01-12 06:05

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

查看更多
小情绪 Triste *
3楼-- · 2019-01-12 06:11

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.

查看更多
欢心
4楼-- · 2019-01-12 06:18

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);
查看更多
对你真心纯属浪费
5楼-- · 2019-01-12 06:19

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);
查看更多
冷血范
6楼-- · 2019-01-12 06:20

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.

查看更多
登录 后发表回答