-1

I am passing a dynamic variable (a list of elements) and looping through the item. The issue of Cannot navigate to dynamic member arising when I'm trying to interact with the items.

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();
}

What could be the issue, should I define dynamic positions instead of passing it in?

1 Answer 1

0

An IWebElement has no method named FindParent(). But if you are using an extension method, asserts that you're using the extension's namespace;

If you have no extension method, you need to get the parent this way:

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

Or you can create the extension method:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.