我在网站上有元素,如下所示
<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中的每一个,或者在span网站上继续,但SeleniumWebdriver无法点击其中任何一个 . 每次出现错误时,我都尝试点击span和on div并使用ng-click事件buch:
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");
它只适用于我放入睡眠并手动向下滚动的情况 . 我不明白 .
3 回答
根据你的回复:
您必须 scroll down 才能让您的脚本可以使用该Web元素 . 为此,您可以使用以下代码:
在这里,您可以从代码中调用此方法 .
然后,您可以使用此代码与Web元素进行交互:
我经历了很多这样的问题,正如Ankur所说,在点击之前使用等待
其中一种方法是ExpectedConditions命令
更多例子可以在http://toolsqa.com/selenium-webdriver/wait-commands/找到