Reputation: 367
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();
Upvotes: 0
Views: 375
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();
You can find a couple of relevant detailed discussions in:
Upvotes: 0