2016-03-29 25 views
0

Web要素のリストをループして、各要素を1つずつクリックしようとしています。デバッグモードでは、目的の要素がメソッドにパラメータとして渡されていることを明確に確認できますが、プログラムは常にリストの最初の要素をクリックしています。IwebElementの子要素をクリックしてください。Selenium/C#

private void CompleteForm(IWebElement element) 
    { 
     if (element == null) throw new ArgumentNullException(nameof(element)); 

     //Open the form and wait for it to load 

     Wait.Until(
      ExpectedConditions.ElementToBeClickable(
       element.FindElement(By.XPath("//td/a[contains(@href, '/Shop')]")))).Click(); 
     Wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("SaveShop"))); 

     //Store the original values 
     GetTheValues(); 

     //Submit the save button 
     Wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("SaveShop"))).Click(); 
     Browser.Navigate().Back(); 
    } 

答えて

1

あなたがしようとしていることはわかりません。しかし、element.FindElement(By.XPath("//td/a[contains(@href, '/Shop')]"))に電話すると、子孫の中で相対検索をelementにしたいと思っています!

もしそうなら、//の前に.を指定する必要があります。それ以外の場合は、ドキュメント全体を検索しています。

固定コード:

Wait.Until(
    ExpectedConditions.ElementToBeClickable(
     element.FindElement(By.XPath(".//td/a[contains(@href, '/Shop')]")))).Click(); 
関連する問題