【发布时间】:2020-07-29 20:55:23
【问题描述】:
我只在 chrome 浏览器中收到此错误:
element not interactable: element has zero size (Session info: chrome=84.0.4147.105)
当我尝试点击<a href="/cart" class="button--counter header__mini-basket" ...></a>时。
这是我的 DOM 中的 sn-p:
<nav class="header__navigation">
<div class="user-section">
<ul class="user-section__list">
<li class="user-section__item user-section__item-my-account js-my-account">
My account<ul class="dropdown dropdown__my-account-desktop">
<li>
<div class="spacer"></div>
</li>
<li>
<div class="arrow-up"></div>
</li>
<li>
<a href="/my-account" role="button" class="my-account__link button button--inverse atm-nav-account" title="My account details">
My account details</a>
</li>
<li>
<a href="/logout" class="logout__link button button--inverse atm-nav-logout" role="button" title="Log out ">
Log out</a>
</li>
</ul>
</li>
<li class="user-section__item">
<a href="/wishlist" class="header__my-wishlist-link atm-nav-wishlist" title="Wishlist">
Wishlist</a>
</li>
<li class="user-section__item dropdown">
<a href="/cart" class="button--counter header__mini-basket" data-toggle="dropdown" data-close-on-bounce="false" data-toggle-status="closed" data-toggle-has-overlay="">
<span class="counter-bubble">
<span class="counter-bubble__quantity">
<span class="cart-counter-wrapper" style="display: inline;">
<span class="counter-bubble__quantity cart-counter" data-counter-type="cart-counter">1</span>
</span>
<span data-counter-type="cart-title">
My cart</span>
</span>
</span>
</a>
<div class="my-account__background-overlay js-account-background-overlay display-none"></div>
</div>
</nav>
我尝试过以不同方式定位元素:
li.user-section__item a.header__mini-basket
ul.user-section__list a.header__mini-basket
div.user-section a.header__mini-basket
nav.header__navigation a.header__mini-basket
但没有任何帮助。
这是我在测试中的:
clickOnMiniBasketIcon(){
this.cartIcon.waitForExist(TIMEOUT_5000_MS);
this.cartIcon.waitForDisplayed(TIMEOUT_5000_MS);
this.cartIcon.waitForEnabled(TIMEOUT_5000_MS);
this.cartIcon.scrollIntoView({block: "center"});
this.cartIcon.waitForClickable({timeout: TIMEOUT_3000_MS});
this.cartIcon.click();
}
我正在使用 webdriverio 5 和 cucumber。
有趣的是,针对 firefox 运行测试通过就好了(无头或非无头版本),但在 chrome 中(无头或非无头版本)我收到此错误。
另外我必须提到,测试调整窗口大小以使用以下命令模拟移动/响应能力:browser.setWindowSize(300, 700);
有人知道如何为 chrome 解决这个问题吗?有人遇到过类似问题吗?
非常感谢任何形式的帮助。
谢谢!
【问题讨论】:
-
您是否尝试在较低版本的 chrome 中运行测试? chrome 84 相对较新。
-
当 chrome 版本为 80.xxx(即在无头模式下的服务器上)时,测试通过就好了。在本地,我一直在寻找如何降级我的 chrome 浏览器版本,结果发现这并不是那么简单,或者在一台机器上拥有 2 个不同版本的 chrome(例如版本 80.xxx 和版本 84.xxx)。
标签: google-chrome webdriver-io