简体   繁体   中英

How to click on <input> type button C#

I tried to click on by .css/by classname but unfortunately, it didn't work...

<div class="col-xs-12">
  <input type="submit" name="commit" value="save" class="pp-btn pp-btn-primary w-70 save-item-description" data-disable-with="saving...">
  <a class="pp-btn pp-btn-danger w-70" data-disable-with="..." data-target="#item-ebay_details" data-remote="true" href="/items/468056.html?partial=ebay_details">cancel</a>
</div>

I need to Click() on and it would be best to track it by class name...

You can use xpath selector to find by class name:

driver.FindElement(By.Xpath(//input[@class='submit']);

Remember, you element might not be yet ready/present/clickable at the point of getting reference to it, that's why you need to either use IMPLICIT or EXPLICIT wait (it is very well documented, search for it)

You can wait for element to be clickable this way:

new WebDriverWait(Driver.Instance, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementExists((By.XPath(//input[@class='submit']))));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM