2

Web API サービスから Selenium PhantomJS ドライバーを実行する権限に問題があると思います。さまざまな管理者アカウントを使用してサービスの偽装を試みましたが、それでも同じエラーが発生します。エラーをスローしている構成ファイルを特定するにはどうすればよいですか? process.StandardOutput.ReadToEnd() を印刷すると、このエラーが発生します。

System.Configuration.ConfigurationErrorsException: Configuration system failed to  initialize
  ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Access is denied.
  ---> System.Security.SecurityException: Access is denied.
   at System.Security.Principal.WindowsIdentity.SafeImpersonate(SafeTokenHandle userToken, WindowsIdentity wi, StackCrawlMark& stackMark)
   at System.Security.Principal.WindowsIdentity.SafeRevertToSelf(StackCrawlMark& stackMark)
   at System.Security.Principal.WindowsIdentity.Impersonate(IntPtr userToken)
   at System.Configuration.ClientConfigurationHost.Impersonate()
4

1 に答える 1

2

Web Driver では構成ファイルを動的に変更する必要がないため、これは非常に奇妙です。あなたは自分ですべてをやろうとしていると思います.車輪を再発明しないでください.これらのことはすべてSeleniumサポートクラスによって既に行われているからです.

Web Api で WebDriver をパイロットするには:

  • Web API プロジェクトの作成/追加
  • Nuget パッケージへの参照を追加するSelenium WebDriver Support Classes
  • アクションに Web ドライバー コードを追加する

https://stackoverflow.com/のタイトルを取得する非常に基本的な方法は次のとおりです。

using OpenQA.Selenium;
using OpenQA.Selenium.PhantomJS;
...
public string Get()
{
    // c:\phantomjs contains phantomjs.exe
    // if blank, Web Driver will download the latest version
    IWebDriver driver = new PhantomJSDriver(@"c:\phantomjs");
    driver.Navigate().GoToUrl("https://stackoverflow.com/");
    string title = driver.Title;
    driver.Quit();
    return title;
}
  • それで全部です !

ホスティングによっては、phantomjs を単独で起動しようとすると、サポート クラスに問題が発生する場合があります。アプリケーション プール ID をパワー ユーザーに変更するだけです。

于 2013-09-12T07:52:09.777 に答える