2016-05-31 9 views
-1

動的変数(要素のリスト)を渡してアイテムをループしています。私がアイテムとやり取りしようとしているときに発生するCannot navigate to dynamic memberの問題。FIndParentエラー - 動的メンバーにナビゲートできません

public void definePositions() 
{ 
    var positions = PanelPositionsContent.FindElements(By.CssSelector("span[class='cell cell-id-symbol']"));    
    CheckEntryPrice(positions); 
} 


private void CheckEntryPrice(dynamic positions) 
{ 
    foreach (var position in positions) 
    { 
     if (position.Text.ToLower().Equals(ScenarioContext.Current["symbol"].ToString().ToLower())) 
     { 
      CommonMethods.Log("Successfully: " + ScenarioContext.Current["symbol"]); 
     } 

     if (position.FindParent().FindElement(By.CssSelector("span[class='cell cell-id-price']")).Text.Equals(ScenarioContext.Current["price"])) 
     { 
      CommonMethods.Log("Failing test, : " + ScenarioContext.Current["price"] + ", actual price" + 
       positions[0].FindParent().FindElement(By.CssSelector("span[class='cell cell-id-price']")).Text); 
      Assert.Fail("Price is not correct"); 
     } 

     CommonMethods.Log("Passed test, clicked price matches position price: expected price: " + ScenarioContext.Current["price"] + ", actual price: " + 
          positions[0].FindParent().FindElement(By.CssSelector("span[class='cell cell-id-price']")).Text); 
    }//calaculate points from curr price to entry 

    CheckGross(); 
} 

私はdynamic positionsを渡すのではなく、それを定義する必要がありますか?

答えて

0

IWebElementにはFindParent()という名前のメソッドがありません。しかし、拡張メソッドを使用している場合は、であると主張します。拡張の名前空間を使用します。

あなたは何の拡張メソッドを持っていない場合は、あなたが親をこのように取得する必要があります:

yourIWebElement.FindElement(By.XPath("..")) 

それとも、拡張メソッドを作成することができます

public static IWebElement FindParent(this IWebElement e, int parentLevel = 1) 
{ 
    return (e == null || parentLevel <= 0) 
      ? e 
      : e.FindElement(By.XPath("..")).FindParent(--parentLevel); 
} 
関連する問題