【问题标题】:How to click on button type "submit" using Selenium and C#如何使用 Selenium 和 C# 点击按钮类型“提交”
【发布时间】:2020-07-10 17:50:35
【问题描述】:

代码试验:

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

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

这是错误信息:

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>

这是按钮的 HTML 代码:

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

已准备好找到该元素但无法单击或无法提交该按钮

【问题讨论】:

  • 使用element.Submit();方法
  • @LộcNguyễnTấn 我添加了闭合三角括号以使节点成为有效节点。如果更改看起来不错,请告诉我。

标签: c# selenium xpath css-selectors webdriverwait


【解决方案1】:

单击元素,因此您必须为所需的 ElementToBeClickable 诱导 WebDriverWait,您可以使用以下任一Locator Strategies 作为解决方案:

  • 使用 CssSelectorSubmit():

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

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

【讨论】:

    【解决方案2】:

    请尝试以下解决方案:

    IWebElement element = driver.FindElement(By.Xpath("//button[contains(text(),'Tiếp Tục')]"));
    
    Actions action = new Actions(Driver);
    action.MoveToElement(element).Perform();
    action.Click();   
    

    【讨论】:

      猜你喜欢
      • 2021-09-24
      • 1970-01-01
      • 1970-01-01
      • 2020-09-22
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 1970-01-01
      • 2013-04-10
      相关资源
      最近更新 更多