0

How to click Update button with no ID using C# Selenium?

<input type="button" value="Update" onclick="javascript:__doPostBack('ctl00$ContentPlaceHolder8$GridView1','Update$0')">

I used the code below but it does not work:

driver.FindElement(By.XPath("//*[@id='ContentPlaceHolder8_GridView1']/tbody/tr[2]/td[6]/input")).Click();

enter image description here

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
lance2k
  • 357
  • 1
  • 4
  • 14

1 Answers1

0

The desired element is n __doPostBack enabled element. So to Click() on the element you have to induce WebDriverWait for the ElementToBeClickable() and you can use either of the following Locator Strategies:

  • CssSelector:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("input[value='Update'][onclick*='ContentPlaceHolder']"))).Click();
    
  • XPath:

    new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//input[@value='Update' and contains(@onclick, 'ContentPlaceHolder')]"))).Click();
    

Reference

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352