0

I want to pass variable to element. My html is like

<input class="form-control" data-bind="textInput: code, attr: { id: 'myTable_code_' + $index() }" type="text" id="myTable_code_0" style="">

I declared element like

  [FindsBy(How = How.Id, Using = "myTable_code_" + myVariable), CacheLookup]
  private HtmlElement _Code;

But offcourse that is not working. Has anyone idea on how to pass varialbe to attribute. I am using c#

James
  • 1,827
  • 5
  • 39
  • 69

2 Answers2

1

You can't do that, Annotations are constant values stored in the class file. You can't compute them at runtime.

Below should work:- Using = "myTable_code_0")

See Can the annotation variables be determined at runtime?

Though, it is for java, but i think it hold true for C# also.

sunny_teo
  • 1,961
  • 1
  • 7
  • 11
0

Instead of using finds by, how about string format? You will need to adjust this a bit based on your setup but depending on what you want to do with the value, you could do something like this...

        string myVariable = "blah";
        string value =  Browser.FindElement_byXPath(string.Format("//input[@id='myTable_code_0']//h4[contains(text(), '{0}')]", myVariable)).Text;
Dazed
  • 1,527
  • 1
  • 13
  • 25