2016-12-17 6 views
1

Visual Studio with Seleniumを使用して、Webページに移動し、配列の内容がページにあるかどうかを調べるアプリケーションを作成しています。私は配列の内容のページを検索する問題に遭遇しています。今は何も見つからないので、次のページに移動してはいけません。Selenium find array contents on page

この配列は読み込み中のCSVファイルから取得され、CSVファイルのレコードの一致をページで検索して停止する必要があります。ここで

は、私がこれまで持っているものです:私はコメントを残しているだろうが、まだに許可されていないのです

 OpenFileDialog ofd = new OpenFileDialog(); 
    private double timeOut; 

    private void bttnImportBrowse_Click(object sender, EventArgs e) 
    { 
     ofd.Filter = "CSV|*.csv"; 
     var fileInputs = new List<string>(); 
     if (ofd.ShowDialog() == DialogResult.OK) 
     { 
      String chosenFile = ofd.FileName; 
      String safeFileName = ofd.SafeFileName; 

      try 
      { 
       // Create an instance of StreamReader to read from a file. 
       // The using statement also closes the StreamReader. 
       using (StreamReader sr = new StreamReader(chosenFile)) 
       { 
        string line; 
        // Read and display lines from the file until the end of 
        // the file is reached. 
        while ((line = sr.ReadLine()) != null) 
        { 
         //Console.WriteLine(line); 
         fileInputs.Add(line); 
         //Console.Write(string.Join(" ", fileInputs)); 

         var driver = new ChromeDriver(@"C:\Users\andre_000\Documents\Visual Studio 2015\Projects\MyProject\"); 


          driver.Navigate().GoToUrl("MySite"); 


         var WebDriverWait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeOut)).Until(ExpectedConditions.ElementExists((By.XPath("/html/body/a[2]")))); 
         while (1==1) { 
          try 
          { 
           var result = driver.FindElement(By.LinkText(fileInputs.ToString())); 
           break; 
          } 
          catch (NoSuchElementException n) 
          { 
           var nextBttn = driver.FindElementByXPath("/html/body/a[2]"); 
           nextBttn.Click(); 
          } 
         } 

        } 
       } 

      } 
      catch (Exception entry) 
      { 
       // Let the user know what went wrong. 
       Console.WriteLine("The file could not be read:"); 
       Console.WriteLine(entry.Message); 
      } 
     } 
    } 

答えて

0

は申し訳ありません。あなたはCSVファイルを持っていますか?

リンクテキストが間違っていると思われます。

現在

var result = driver.FindElement(By.LinkText(fileInputs.ToString())); 

おそらく

var result = driver.FindElement(By.LinkText(line)); 
+0

あなたのVaRのドライバを移動する必要があり、リスト上のToString()を呼び出す=新しい(C "@ ChromeDriver:ドキュメントは、Visual Studioを\ \ Users \ユーザーandre_000 \ 2015 \ Projects \ MyProject \ "); – BenBlanch

+0

おそらくバックグラウンドスレッドに置くべきでしょう。そこには多くの例がオンラインです。 Winformsで実行している場合は、読み取りループでApplication.DoEvents()を呼び出してエラーを停止できます。 (私はそれが悪い形だと思う)https://msdn.microsoft.com/en-us/library/system.windows.forms.application.doevents(v=vs.110).aspx – BenBlanch

+0

" 「ライン」が問題になっています。いずれのレコードでもなく、CSVファイルから最初のレコードのみを検索しています。例:ファイルには、apple、banana、orangeというレコードがあります。それはリンゴを探して、バナナとオレンジの上をスキップするだけです –