【发布时间】:2018-10-26 03:20:57
【问题描述】:
我在网站上有一个元素,如下所示
<div id="wrapperCategory" class="categoryItemWrapper">
<div class="panel panel-default panel-categoryItem text-center categoryItem disabledItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category">
<div class="panel-heading">
Category
</div>
<div class="panel-body">
Price
</div>
<div class="panel-footer availability" ng-class="category.AvailabilityStyleClass">
<span ng-bind-html="category.AvailabilityText">Avail</span>
</div>
</div>
</div>
我需要点击它才能前进。如果我手动单击每个这些 div 或跨网站继续前进,但 SeleniumWebdriver 无法单击其中任何一个。 每次出现错误时,我都尝试使用 ng-click 事件单击 span 和 div:
Exception in thread "main" org.openqa.selenium.WebDriverException: Element <div class="panel panel-default panel-categoryItem text-center categoryItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category"></div> is not clickable at point (619.2666625976562, 474.23333740234375). Other element would receive the click: <div style="top: 0;left: 0;bottom: 0;right: 0;position: fixed;pointer-events: auto !important;z-index: 10000;" id="cover-1526454140024"></div>
我不明白。 我可以以某种方式检查哪个元素是可点击的,哪个元素与我想要点击的元素重叠(我在网站的代码中没有看到任何 id="cover-1526454140024" 的 div)?
更新: 不幸的是,在您的解决方案之后它仍然不起作用。 尝试点击时出现同样的异常。
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
JavascriptExecutor js = (JavascriptExecutor) Mundial.driver;
js.executeScript("arguments[0].scrollIntoView();", categoryItem);
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(categoryItem));
categoryItem.click();
List<WebElement> selects = driver.findElements(By.tagName("select"));
Select ticketsToSelect = new Select(selects.get(3));
ticketsToSelect.selectByValue("number:2");
它仅在我进入睡眠状态并手动向下滚动时才有效。没看懂。
【问题讨论】:
-
尝试在点击事件前添加等待
-
当你的脚本正在运行并且你正在可视化时,你能看到元素并且仍然得到错误吗?或者您是否必须向下滚动或执行某些操作才能查看元素交互。
-
添加您的代码试验,这会很有帮助
-
@cruisepandey 这就是解决方案。我没有看到这个元素,需要向下滚动然后它才能工作。谢谢:)