lance2k
lance2k

Reputation: 367

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

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

Upvotes: 0

Views: 375

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193338

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:

Upvotes: 0

Related Questions