C# 如何使用SeleniumWebDriver C单击展开按钮打开节#

C# 如何使用SeleniumWebDriver C单击展开按钮打开节#,c#,testing,selenium-webdriver,selenium-chromedriver,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" require

单击展开按钮打开列出分类法复选框的页面部分时遇到问题。
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>
结果:Webdriver通过了该步骤,但是屏幕上没有发生任何事情,展开按钮仍然折叠,选项仍然隐藏

尝试2:我尝试了MoveToElement操作

Actions clickExpand = new Actions(driver);
clickExpand.MoveToElement(driver.FindElement(By.Name("resourceModelTaxonomyTypeIds"))).Click().Perform();
结果:和以前一样,webdriver认为一切正常,但实际上“展开”按钮仍然没有展开该部分

尝试3:安装了Selenium IDE,录制并回放了代码(通过转换为C#) Selenium IDE使用
记录它。单击()
操作,就像我在上面的尝试1中尝试的一样

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


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

我想知道该元素是否已变得可单击?您是否尝试过使用WebDriverWait并带有预期条件标志?一些示例代码。这里有更多参考资料


事实证明,对于这种类型的展开按钮,如果您实际跟随GlypionChevron并单击它,则操作将执行

driver.FindElement(
            By.CssSelector(
                ".glyphicon.glyphicon-chevron-right")).Click();
当按钮折叠时,V形符号为“右”,当展开时,V形符号为“下”,因此理论上,如果有多个展开,可以重复相同的代码,该代码将展开所有的按钮。。。或者更聪明一点,与父母交往,但两者都起作用

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

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

您是否尝试过使用javascript执行单击?使用ExecuteScript命令?有一次作为
((IJavaScriptExecutor)驱动程序进行了第三次尝试。ExecuteScript(“参数[0]。单击()”,driver.findelee(By.Name(“ResourceModelTaxonomyTypeId”)并让我知道,并确保提供的用于查找按钮的名称是唯一的,并且找到了您想要的正确按钮:)
driver.FindElement(
            By.CssSelector(
                ".glyphicon.glyphicon-chevron-right")).Click();
driver.FindElement(
                By.CssSelector(
                    ".glyphicon.glyphicon-chevron-down")).Click();