如何单击展开按钮以使用 Selenium Webdriver C# 打开一个部分
How to click an Expand button to open a section using Selenium Webdriver C#
我在单击“展开”按钮时遇到问题,该按钮会打开列出分类复选框的页面部分。
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 似乎没有这样做。
我想知道该元素是否已变得可点击?您是否尝试过使用 WebDriverWait 和 Expected Condition 标志?一些示例代码。更多参考在这里 http://selenium-python.readthedocs.io/waits.html?highlight=webdriverwait
try:
more = WebDriverWait(self.driver, 10,poll_frequency=2,ignored_exceptions=[ElementNotVisibleException, ElementNotSelectableException]).until(EC.element_to_be_clickable((By.Name, 'resourceModelTaxonomyTypeIds')))
except TimeoutException:
break
more.click()
事实证明,对于这种类型的展开按钮,如果您实际上是在 glyphion-chevron 之后点击它,那么操作会执行...
driver.FindElement(
By.CssSelector(
".glyphicon.glyphicon-chevron-right")).Click();
当按钮折叠时 V 形是 "right",当展开时 V 形是 "down",所以理论上如果你有多个展开,你可以重复相同的代码来展开所有他们...或者变得更聪明并与 parent 联系起来,但两者都有效。
单击以折叠您需要的屏幕区域....
driver.FindElement(
By.CssSelector(
".glyphicon.glyphicon-chevron-down")).Click();
我在单击“展开”按钮时遇到问题,该按钮会打开列出分类复选框的页面部分。
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 似乎没有这样做。
我想知道该元素是否已变得可点击?您是否尝试过使用 WebDriverWait 和 Expected Condition 标志?一些示例代码。更多参考在这里 http://selenium-python.readthedocs.io/waits.html?highlight=webdriverwait
try:
more = WebDriverWait(self.driver, 10,poll_frequency=2,ignored_exceptions=[ElementNotVisibleException, ElementNotSelectableException]).until(EC.element_to_be_clickable((By.Name, 'resourceModelTaxonomyTypeIds')))
except TimeoutException:
break
more.click()
事实证明,对于这种类型的展开按钮,如果您实际上是在 glyphion-chevron 之后点击它,那么操作会执行...
driver.FindElement(
By.CssSelector(
".glyphicon.glyphicon-chevron-right")).Click();
当按钮折叠时 V 形是 "right",当展开时 V 形是 "down",所以理论上如果你有多个展开,你可以重复相同的代码来展开所有他们...或者变得更聪明并与 parent 联系起来,但两者都有效。
单击以折叠您需要的屏幕区域....
driver.FindElement(
By.CssSelector(
".glyphicon.glyphicon-chevron-down")).Click();