【问题标题】:Element is not clickable at point (80, 82). Other element would receive the click元素在点 (80, 82) 处不可点击。其他元素会收到点击
【发布时间】:2021-06-09 12:45:59
【问题描述】:

我有一个 Angular 应用程序,我想使用 Java 和 Selenium Web 驱动程序实现自动化。在我的情况下,我有一个显示在进度条之后的选项卡:

    // Wait Progress bar to finish
    new WebDriverWait(driver, 30).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[@class='ngx-loading-text center-center' and starts-with(., 'Loading')]")));

    // Listener to click on the tab:

    WebDriverWait webDriverWait = new WebDriverWait(driver, 25);
    System.out.println("Click on Tab " + name + " using id locator " + tabId);
    WebElement webElement = webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id(tabId)));
    webElement.click();

在图形模式下它工作正常。但是当我尝试将它运行到无头 Chrome 模式的后台时,我得到了异常:

element click intercepted: Element <div cdkmonitorelementfocus="" class="mat-tab-label mat-ripple mat-tab-label-active ng-star-inserted" mat-ripple="" mattablabelwrapper="" role="tab" id="mat-tab-label-0-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-0-0" aria-selected="true" aria-disabled="false">...</div> is not clickable at point (80, 82). Other element would receive the click: <video width="240" height="320" controls="">...</video>
  (Session info: chrome=90.0.4430.212)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DTXA-ENVTEST01', ip: 'xxxxxxxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_291'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 90.0.4430.212, chrome: {chromedriverVersion: 90.0.4430.24 (4c6d850f087da..., userDataDir: C:\Users\devadmin\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:51589}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 27f7f44c1429bbda4e137629c2f9ae52

堆栈跟踪

org.openqa.selenium.ElementClickInterceptedException: 
element click intercepted: Element <div cdkmonitorelementfocus="" class="mat-tab-label mat-ripple mat-tab-label-active ng-star-inserted" mat-ripple="" mattablabelwrapper="" role="tab" id="mat-tab-label-0-0" tabindex="0" aria-posinset="1" aria-setsize="3" aria-controls="mat-tab-content-0-0" aria-selected="true" aria-disabled="false">...</div> is not clickable at point (80, 82). Other element would receive the click: <video width="240" height="320" controls="">...</video>
(Session info: chrome=90.0.4430.212)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DTXA-ENVTEST01', ip: 'xxxxxxxx', os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_291'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 90.0.4430.212, chrome: {chromedriverVersion: 90.0.4430.24 (4c6d850f087da..., userDataDir: C:\Users\devadmin\AppData\L...}, goog:chromeOptions: {debuggerAddress: localhost:51589}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webauthn:extension:largeBlob: true, webauthn:virtualAuthenticators: true}
Session ID: 27f7f44c1429bbda4e137629c2f9ae52
at org.mobile.LoginScreenTest.verifyMainMenuLandingScreenTest(LoginScreenTest.java:411)

可能是什么问题?在这种情况下,有没有比elementToBeClickable 更合适的ExpectedConditions

看起来进入无头模式,进度动画不会暂停,并且会产生不可变的点击。能给个建议吗?

【问题讨论】:

  • 你用来点击的定位器对吗?
  • @PeterPenzov :将其更新为答案。谢谢!

标签: selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

没有看到失败的截图很难猜测,但我会尝试。
我认为有几件事情会有所帮助。

  1. 启动浏览器最大化
options.addArguments("start-maximized");
  1. 使用元素可见性而不是可点击性
WebElement webElement = webDriverWait.until(ExpectedConditions.elementToBeVisible(By.id(tabId)));
webElement.click();
  1. 使用 JavaScript 点击而不是 WebDriver 点击
WebElement webElement = webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id(tabId)));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", webElement);

【讨论】:

    【解决方案2】:

    试试下面的代码:

    new Actions(driver).moveToElement(webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id(tabId)))).click().build().perform();

    两者都有(带有 UI 和 Headless)

    【讨论】:

    • 我使用的是最新的稳定版 maven:&lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt; &lt;artifactId&gt;selenium-java&lt;/artifactId&gt; &lt;version&gt;3.141.59&lt;/version&gt; 最新的 beta 版本可能会解决这个问题吗?
    • 好吧,Element is not clickable at point (X, Y). Other element would receive the click 是一个通用错误,Selenium 难以在其当前视口内聚焦。 Actions 类让驱动程序专注于我们想要交互的元素。这不是错误。
    猜你喜欢
    • 2016-12-19
    • 2015-01-12
    • 2016-06-08
    • 2017-04-16
    • 1970-01-01
    • 2018-03-16
    • 1970-01-01
    • 2017-11-27
    相关资源
    最近更新 更多