如何使用Selenium Webdriver C#单击“展开”按钮打开一个部分#

时间:2016-08-11 14:54:24

标签: 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认为一切正常,但实际上,“展开”按钮仍未扩展该部分。

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

我有点坚持为什么这个特定按钮无法工作。有没有人遇到这个或处理过这些类型的扩展按钮?

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

1 个答案:

答案 0 :(得分:0)

我想知道该元素是否已成为可点击的?您是否尝试过使用WebDriverWait和预期条件标志?一些示例代码。更多参考资料enter image description here

        $("UpdateTableTop").click(function (e) {                
           var selectedModels = [];

           // Get all of the rows that were selected

           // Loop through each row, create an object and add to array
           for(var i = 0; i < numItemsSelected; i++)
           {
              // Make sure the properties of the model match your definition of SampleModel
               var currentModel = {
                                      Reconciled = ??? , //Reconciled from the current row
                                      StudentID = ???
                                   };
               selectedModels.push(currentModel);
           }

            $.ajax({
                url: '@Url.Action("UpdateTable")',
                data: /* pass in the list of models (selectedModels) */,
                success: function (){
                    console.log("Success!");
                }
            });
        });