c# - 如何单击展开按钮以使用 Selenium Webdriver C# 打开一个部分

标签 c# testing selenium-webdriver selenium-chromedriver

我在单击“展开”按钮时遇到问题,该按钮会打开列出分类复选框的页面部分。
似乎 webdriver 认为它正在执行单击展开按钮的操作,但该部分保持折叠状态。
以下是 HTML 的一部分

代码

metadata-editor name="resourceModelTaxonomyTypeIds" label-text="Type" matadata-fieldname="Type" resource-id="id" selected-ids="resourceModel.TaxonomyTypeIds" required class="ng-isolate-scope"
<div class="form-group" ng-class="{'has-error': (required && form.$submitted && !isValid)}"
  ::before
  <div class="col-md-9">
  <!-- ngRepeat: node in loadSelectedNodes() -->
  <br ng-show="loadSelectedNodes().length > 0" class="ng-hide"
  <button type="button" class="btn btn-sm btn-info btn-expand-taxonomy ng-pristine ng-binding ng-invalid ng-invalid-valid ng-touched" name="resourceModelTaxonomyTypeIds" ng-model="selectedIds" ng-click="toggleView(isCollapsed)"><span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> Expand</button>

以下是我的一些未奏效的工作:

尝试 1:我尝试了简单的 .Click() 操作

driver.FindElement(By.Name("resourceModelTaxonomyTypeIds")).Click();

结果:Webdriver 通过了这一步,但是屏幕上没有任何反应,展开按钮仍然折叠并且选项仍然隐藏。

尝试 2:我尝试了 MoveToElement 操作

Actions clickExpand = new Actions(driver);
clickExpand.MoveToElement(driver.FindElement(By.Name("resourceModelTaxonomyTypeIds"))).Click().Perform();

结果:和之前一样,webdriver认为一切正常,但实际上Expand按钮仍然没有展开section。

尝试 3:安装 Selenium IDE,进行录制和回放以查看其编码内容(通过转换为 C#) Selenium IDE 使用 .Click() 操作记录它,正如我在上面的尝试 1 中尝试的那样。

我有点不明白为什么这对这个特定按钮不起作用。有没有人遇到过这种情况或处理过这些类型的展开按钮?

注意:通过单击以证明按钮正常工作来手动测试展开按钮,只是 webdriver 似乎没有这样做。

最佳答案

事实证明,对于这种类型的展开按钮,如果您真的找到 glyphion-chevron 并单击它,那么该操作将执行...

driver.FindElement(
            By.CssSelector(
                ".glyphicon.glyphicon-chevron-right")).Click();

当按钮折叠时,人字形是“右”,展开时人字形是“下”,所以理论上如果你有多个展开,你可以重复相同的代码来展开所有的......或者是更聪明并与 parent 交往,但两者都有效。

单击以折叠您需要的屏幕区域....

driver.FindElement(
                By.CssSelector(
                    ".glyphicon.glyphicon-chevron-down")).Click();

关于c# - 如何单击展开按钮以使用 Selenium Webdriver C# 打开一个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38899799/

相关文章:

c# - 基于接口(interface)的匿名类型

c# - 使相机跟随可以以恒定的高度和速度绕球体飞行

C# 委托(delegate)定义 - 匿名方法与正式定义的方法

c# - asp.net中的后台函数

c++ - 与阻塞调用同步

ruby-on-rails - 如何在我的 Rails 应用程序中测试 ActiveRecord::RecordNotFound?

maven - 从 Maven 启动 H2 数据库服务器?

c# - ExpectedConditions.InvisibilityOfElementLocated 需要更多时间

Python 3 + Selenium : Clicked the element but nothing happen

java - 如何使用 selenium webdriver 在同一浏览器的另一个选项卡上打开 url?