title: Selenium c#: What is the best way to get a new instance of a RemoteWebElement without using the autoID / Class, Instance etc?
body: <p>How can I refresh my RemoteWebElements in c# / selenium?</p>
  <p>I have 2 Methods...</p>
  <pre><code>    public static bool ClickMe_Method_1(WindowsDriver&lt;RemoteWebElement&gt; driver, RemoteWebElement button_ToClick)
      {
          //Click
          button_ToClick.Click();
  
          //Assert the click worked and the button is now not Enabled
          Assert.IsFalse(button_ToClick.Enabled);//This Assert will never work because button_ToClick variable is now out of date and needs to be refreshed in this code somehow.
          return button_ToClick.Enabled;
      }
  
      public static bool ClickMe_Method_2(WindowsDriver&lt;RemoteWebElement&gt; driver, RemoteWebElement button_ToClick, string automationID)
      {
          //Click
          button_ToClick.Click();
  
          //This line refreshes the button_ToClick
          //BUT is there a way to do this without passing the automationID? 
          //This is a simple example and will only work where I want to click        
          //the first or only instance of a button with this automation ID so 
          //this solution is not very scalable.
          button_ToClick = driver.FindElementByAccessibilityID(automationID);
  
          //Assert the click worked and the button is now not Enabled
          Assert.IsFalse(button_ToClick.Enabled);
          return button_ToClick.Enabled;
      }
  </code></pre>
  <p>In the above code, method1 will always fail because the &quot;button_ToClick&quot; has not been updated in my test solution after it was clicked. So if the click works and the button_ToClick Enabled becomes false, my code will not know Enable has now become = false.</p>
  <p><strong>My question is this</strong>: Do I have to pass in the automation ID and use a FindElement approach to find the latest (as in method 2) OR is there a way I can ask selenium to update the button_ToClick that I have.</p>
  <p><strong>NB</strong>: The RemoteWeElement (button_ToClick in my case) does not have the auto ID. Unless I am missing something, there isn't a way to get it at this stage inside my method without passing the auto ID in separately.</p>
  <p><strong>Background</strong>: The real reason I am asking this question is because the autoID alone sometimes is not enough. I might be testing a table of rows where each row has a button. Let's say the calling method had done some clever work and I know I want to click the 4th button (index = 3 as count is from zero). In this case I would need a 3rd method (after my 2 methods above) and it would have to know my auto ID AND the instance. This is a pain, less tidy and I will now be introducing testers to this solution and I want the easiest, most readable code.</p>