2017-02-22 17 views
0

SeleniumのChrome WebdriverとC#を使用してWebサイトへのログインを自動化しようとしています。次のコードを実行すると、スクリーンショット1と2に記載されているエラーがスローされます。私は間違って何をしていますか?エラーのグーグルは関連する結果を表示していないようです。Selenium Chrome Webdriverが動作しない

using System.Drawing.Imaging; 
using System.IO; 
using OpenQA.Selenium.Chrome; 

namespace WebDriverTest 
{ 
    class Program 
    { 
     static void Main(string[] args) 
     { 
      // Initialize the Chrome Driver 
      using (var driver = new ChromeDriver()) 
      { 
       // Go to the home page 
       driver.Navigate().GoToUrl("https://twitter.com/");      
       // Get User Name field, Password field and Login Button 
       var userNameField = driver.FindElementById("usr"); 
      } 
     } 
    } 
} 

enter image description here

An unhandled exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll. 
    Additional information: A exception with a null response was thrown 
sending an HTTP request to the remote WebDriver server for 
URL http://localhost:61724/session/cc7bae393b288855ed8169dade774baa/element. 
The status of the exception was ReceiveFailure, and the message was: 
The underlying connection was closed: An unexpected error occurred on a receive. 

enter image description here

+0

私はこれがバージョンの不一致だと思います。あなたが使用しているchromeとchromeのドライバのバージョンは何ですか? 私は最新のchrome 56とchrome driver 2.28で試してみることをお勧めします。 57クロムのようないくつかの問題があるかもしれないように見えます。 –

答えて

0

あなただけGoToUrl後にページの読み込みを待たなければならない:私はロードするためにページを待つでしょう

driver.Manage().Timeouts().SetPageLoadTimeout(TimeSpan.FromSeconds(10)); 
+0

異なるエラーを取得しても似たような結果を得る:WebDriver.dllで 'OpenQA.Selenium.WebDriverException'の未処理例外が発生しました 追加情報:予期しないエラー。 System.Net.WebException:リモートサーバーに接続できません---> System.Net.Sockets.SocketException:ターゲットマシンが積極的にそれを拒否したため、接続できませんでした:: 1:62419 –

0

public static void WaitForElementLoad(By by, int timeoutInSeconds) 
{ 
    if (timeoutInSeconds > 0) 
    { 
     WebDriverWait wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(timeoutInSeconds)); 
     wait.Until(ExpectedConditions.ElementIsVisible(by)); 
    } 
} 

curtosey How to wait for element to load in selenium webdriver?

0

ChromeとChromeDriverのあなたのバージョンを確認します。互換性hereを参照してください。また、あなたのSeleniumのバージョンが古くなっていないことを確認してください。これらのタイプのエラーは通常、バージョンの互換性のためです。参考のため

、現在latestsの:

Chrome 56.0... 
ChromeDriver 2.27 
Selenium WebDriver 3.1.0 
0

それは明らかです!

idが "usr"のページ "http://twitter.com"に要素がありません。

あなたは何を探していますか? id属性が "usr"に設定されていて、そのような要素が存在しないページ上の要素を探しています。例外はそれを言います

検査要素を行いますplz

関連する問題