2016-05-31 2 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); 
} 
관련 문제