我有一个有滚动的表,如果我想点击需要滚动表的元素,selenium会找到该元素,不会抛出任何异常,但不会点击它。
<table class="table table-hover" fixed-header="" style="height: 175px;">
<tbody style="display: block; height: inherit; overflow: auto;">
<!-- ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
<tr class="ng-scope" ng-repeat="registro in calendario.meses">
<!-- end ngRepeat: registro in calendario.meses -->
</tbody>
</table>
鉴于该表具有属性overflow:auto,一些元素不会显示。
答案 0 :(得分:0)
您可能需要滚动到元素的视图。 Python中的示例:
driver.execute_script("arguments[0].scrollIntoView();", element)
element.click()
或者,移动到该元素并通过"browser actions"点击:
actions = ActionChains(driver)
actions.move_to_element(element).click().perform()
答案 1 :(得分:0)
您可以尝试滚动到表格的末尾:
((JavascriptExecutor) driver).executeScript("var elem = document.getElementByTagName('table'); elem.scrollTop=elem.scrollHeight;");
如果您想慢慢滚动,请尝试:
((JavascriptExecutor) driver).executeScript("var elem = document.getElementByTagName('table'); elem.scrollTop=100;");
滚动到达相对元素后,您可以执行require操作。