简体   繁体   中英

How to click on button type "submit" using Selenium and C#

Code trials:

chrome[row_index].FindElementByXPath("//*[@id=\"app\"]/div/div[1]/div[2]/div[3]/div[2]/div/button").Submit();

and

chrome[row_index].FindElementByXPath("//*[@id=\"app\"]/div/div[1]/div[2]/div[3]/div[2]/div/button").Click();

This is Error Message:

An exception of type 'OpenQA.Selenium.ElementClickInterceptedException' occurred in WebDriver.dll but was not handled in user code element click intercepted: Element <button data-v-7b27a432="" type="submit" class="btn btn-primary btn-sm form-control mt-3">...</button> is not clickable at point (464, 863). Other element would receive the click: <i data-v-5e808f53="" class="font-20 d-block mb-1 icon-question"></i>

This is Html Code Of Button :

<button data-v-7b27a432="" type="submit" class="btn btn-primary btn-sm form-control mt-3">Tiếp Tục</button> .

It ready find that elment but cant click or cant submit that button

Please try below solution :

IWebElement element = driver.FindElement(By.Xpath("//button[contains(text(),'Tiếp Tục')]"));

Actions action = new Actions(Driver);
action.MoveToElement(element).Perform();
action.Click();   

The click on the element so you have to induce WebDriverWait for the desired ElementToBeClickable and you can use either of the following Locator Strategies as solutions:

  • Using CssSelector and Submit() :

     new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.btn.btn-primary.btn-sm.form-control[type='submit']"))).Submit();
  • Using XPath and Click() :

     new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[contains(@class, 'form-control') and text()='Tiếp Tục']"))).Click();

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