Selenium下ChromeDriver中的按钮不接受点击

问题描述 投票:0回答:1

我正在运行硒,使用以下nuGet软件包(DotNetSeleniumExtras.WaitHelpers.3.11.0 NUnit.3.12.0 NUnit3TestAdapter.3.16.1 Selenium.Support.3.141.0 Selenium.WebDriver.3.141.0)。我正在使用Chrome(版本80.0.3987.132(正式版本)(64位))在Windows上运行]

到目前为止,除了一些计时问题之外,其他所有功能都在起作用。但是,如下所述的按钮拒绝接受任何单击。

<mat-card-actions _ngcontent-frq-c15="" class="mat-card-actions" style="margin-top: 3rem">
<button _ngcontent-frq-c15="" color="primary" mat-raised-button="" type="submit" class="mat-raised-button mat-button-base mat-primary" ng-reflect-color="primary"><span class="mat-button-wrapper">Submit</span>
    <div class="mat-button-ripple mat-ripple" matripple="" ng-reflect-centered="false" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLButtonElement]"></div>
    <div class="mat-button-focus-overlay"></div>
</button>
<button _ngcontent-frq-c15="" mat-stroked-button="" type="reset" class="mat-stroked-button mat-button-base"><span class="mat-button-wrapper">Clear</span>
    <div class="mat-button-ripple mat-ripple" matripple="" ng-reflect-centered="false" ng-reflect-disabled="false" ng-reflect-trigger="[object HTMLButtonElement]"></div>
    <div class="mat-button-focus-overlay"></div>
</button>

我已尝试从代码意义上进行所有操作,请参见下文

 string[] selectors =
  {
    ".mat-card-actions .mat-raised-button", ".mat-card-actions .mat-primary",
    ".mat-card-actions .mat-button-wrapper", ".mat-card-actions .mat-button-ripple"
  };
  //
  // string[] selectors = {".mat-card-actions .mat-raised-button"};
  foreach (string selector in selectors)
  {
    IWebElement submitButton = _driver.FindElement(By.CssSelector(selector));
    submitButton.Click();

    try
    {
      submitButton.SendKeys(Keys.Space);
      submitButton.SendKeys(Keys.Return);
    }
    catch (Exception ex)
    {
      log.Error(ex.Message);
    }

    // This doesn't work
    // Configure the Action
    Actions action = new Actions(_driver);
    action.MoveToElement(submitButton).Perform();
    action.MoveToElement(submitButton).Click().Perform();


    // This doesn't work
    var executor = (IJavaScriptExecutor) _driver;
    executor.ExecuteScript("arguments[0].click();", submitButton);

    executor.ExecuteScript("document.querySelector(\".mat-raised-button\").click()");
  }

这些工作都没有。然后我注意到在chrome控制台窗口中执行以下javascript无效。

document.querySelector(\".mat-raised-button\").click()"

[但是,在不是由Selenium驱动的Chrome实例中,这很好用。这是Chrome / Selenium或C#问题吗?在测试中的应用程序中,所有其他按钮单击均正常。我在此问题上失去了2天的服务,因此将不胜感激。

谢谢,

约翰

angular selenium google-chrome button click
1个回答
0
投票

哇,我们解决了这个问题。在页面上,有三张卡片(公司,用户和站点)。在我们的业务逻辑中,可以选择使用与网站相同的公司详细信息,因为除了一个字段外,它们非常相似。开发人员在开发时已在站点区域中为表单(公司)重复使用了相同的验证器。这意味着该字段已在站点中检查,但不存在,因此验证失败。但是,由于UI上没有字段,因此验证失败消息不可见。

希望这将在以后节省人们的时间,这种类型的错误可能会花费大量的团队时间。如果验证消息对用户不可见,我会看到对Angular的一个很好的补充是控制台警告。

© www.soinside.com 2019 - 2024. All rights reserved.