2017-04-02 9 views
0

これは私のコードですC#私は削除ボタンを押して、私が削除したい削除の量を選択し、削除を削除します。 は、おそらく私がどのように依頼することがより正確であり、一方、このdelete要素であれば、それは削除手順を実行することが真の現れとしてC#selenium web driverどのようにwhileループwhile要素で

PropertiesCollections.driver.FindElement (By.LinkText ("Delete")). Click(); 

それがテストを継続していない場合

PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click(); 
new SelectElement(PropertiesCollections.driver.FindElement(By.Id("remove_shares"))).SelectByText("1"); 
PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click(); 

私はそれが削除のすべてのステップを行いますと、それは他のテスト


のために継続していない場合は、削除ボタンが表示される場合はループを作りたいです

イムは、このコード

var links = PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click(); 
      while (links = true) 
       { 
       PropertiesCollections.driver.FindElement(By.LinkText("Delete")).Click(); 
       PropertiesCollections.driver.FindElement(By.Id("remove_shares")); 
       PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click(); 
      } 

と試みるが、私はエラー エラー1は、コードの最初の行が変数に.Click()の復帰を割り当てている暗黙に型付けされたローカル変数

答えて

1

に空間を割り当てることができません取得linksでも.Click()void(何もありません)を返します。

あなたが何をしたいのためのロジックは次のとおりです。[削除]リンクは

  • が存在する場合には、それに
  • をクリックしない場合のもの
  • 繰り返し1-3を行い参照するには

    1. チェック

    IReadOnlyCollection<IWebElement> links = PropertiesCollections.driver.FindElements(By.LinkText("Delete")); // gets a collection of elements with Delete as a link 
    while (links.Any()) // if the collection is not empty, this evaluates to `true` 
    { 
        links.ElementAt(0).Click(); // click the first (and probably only?) element 
        // do stuff 
        PropertiesCollections.driver.FindElement(By.Id("remove_shares")); 
        PropertiesCollections.driver.FindElement(By.XPath("(//button[@type='button'])[2]")).Click(); 
        // get the Delete links again so we can return to the start of the `while` and see if it's still not empty 
        links = PropertiesCollections.driver.FindElements(By.LinkText("Delete")); 
    } 
    
  • +0

    これは私の問題を大きく解決してくれた助けてくれてありがとう、 私はこの行を理解していない質問があります。> Links.ElementAt(0).Click(); //最初の(おそらく唯一の)要素をクリックしてください // do stuff –

    +0

    これは、コレクションの最初の要素をクリックするだけです。詳細は '.ElementAt()'のドキュメントを見てください。 – JeffC

    +0

    この(または任意の)回答が役に立つと判明した場合は、それをアップしてください。これがあなたの質問に答えた場合は、それを受け入れられた回答としてマークしてください。ありがとう! – JeffC