无法单击 GUI 中的'Add'按钮(错误:其他元素将收到单击)



我正在尝试单击'Add'按钮,但收到以下错误消息:

Exception in thread "main" org.openqa.selenium.WebDriverException: unknown 
error: Element <img src="theme/catalogSiemens/images/btn/btnBackCatalog.png" 
alt="Zurück" title="Zurück"> is not clickable at point (53, 57). Other 
element would receive the click: <div id="updateIndicator" 
class="waitVisible"></div>
(Session info: chrome=58.0.3029.110)
(Driver info: chromedriver=2.29.461591 
(62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.10586 
x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 581 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'P3B-BQHT7R1', ip: '10.222.132.78', os.name: 'Windows 
10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, 
mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome=
{chromedriverVersion=2.29.461591 (62ebf098771772160f391d75e589dc567915b233)

我的代码是:

driver.findElement(By.linkText("CMT Desigo CC")).click();
    driver.findElement(By.linkText("Basis")).click();
    driver.findElement(By.xpath("//img[@alt='In den Einkaufswagen 
legen']")).click();
    System.out.println("Item 1 added");
driver.findElement(By.xpath("//img[@alt='Zurück']")).click();

HTML 是:

<a onclick="      if (document.referrer && 
document.referrer.indexOf('cameleonUI') > -1){if 
(Prototype.BrowserFeatures.isAndroid) {history.back();} else {if 
(document.referrer.startsWith(document.baseURI)) 
{location.href=document.referrer; } else {/* do nothing, too risky 
*/}}}else{goBack('close.do?S_moduleContextId=cat');}; return false;
                     "
                    id="tile282_0"
                    actionName="BACK"
                        href="#"
                        target="_blank"
                    class=""  >  <img 
src="theme/catalogSiemens/images/btn/btnBackCatalog.png" alt="Zurück" 
title="Zurück" /> </a>

任何建议将不胜感激。如果需要更多信息,也请告诉我。提前谢谢。

我认为以前的解决方案解决了这个问题,但为了不再随机出现这种行为,您将不得不稍微增加等待时间并重新运行它多次以确保等待时间足够,因为每次运行代码时加载的页面元素都不会相同

您可以通过将 10

增加到 15 或 20 秒来执行此操作:

 WebDriverWait wait2 = new WebDriverWait(driver, 20);
    WebElement element2 = wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//img[@alt='Zurück']")));
    element2.click();

从你得到的异常中,我可以理解你的页面正在加载或某个div正在掩盖你的div元素。为了避免这种情况,您可以等到页面加载(如果在加载页面时使用 fluent 等待该加载器元素时出现某些加载器,直到该元素不可见(或者至少在某些情况下,某些应用程序一次加载多个。所以在这种情况下,线程睡眠。如果有任何问题,请告诉我。

以下是您问题的答案:

从错误堆栈跟踪中可以清楚地看出,元素存在于 DOM 中,但不可单击。这意味着有一个叠加层。因此,要克服这种情况,您必须按如下方式使用ExplicitWait

    WebDriverWait wait2 = new WebDriverWait(driver, 10);
    WebElement element2 = wait2.until(ExpectedConditions.elementToBeClickable(By.xpath("//img[@alt='Zurück']")));
    element2.click();

让我知道这是否回答了您的问题。

最新更新