0

大家好,我在与 e2e 脚本中的表格交互时遇到了一些问题。 element(by.css('#topic_0')).click(); 当我在我的开发环境中时,我可以很好地与之交互,但是当我切换到我的测试环境时与它交互时,我得到了这个错误。 Failed: element click intercepted element id="topic_0" is not clickable at point (x,x). other element would receive the click id="topics_table" 这就是我登录测试环境的方式

 browser.waitForAngularEnabled(false);
    browser.get(browser.baseUrl);
    browser.sleep(10000);
    browser.findElement(by.id('userID')).sendKeys(browser.params.login.user);
    browser.findElement(by.id('password')).sendKeys(browser.params.login.password);
    browser.findElement(by.name('submitButton')).click();
    browser.waitForAngularEnabled(true);
4

1 回答 1

0

当量角器无法找到目标元素时,通常会发生错误Failed: element click intercepted element id="topic_0" is not clickable at point (x,x). other element would receive the click id="topics_table"(在您的情况下,您的目标是具有#topic_0css 的元素;来自上面的代码element(by.css('#topic_0')))...

当您不处理承诺时,量角器通常无法找到元素。我假设您尝试单击的元素在 DOM 上尚不可用,而量角器正在单击另一个元素......这个问题与环境无关。也许在你的情况下,测试环境只是比开发环境慢,这就是为什么它在开发环境上工作,而不是在测试环境上工作。

我会说使用预期条件之一,即预期条件的可见性,以便您的代码最终等待元素显示在 DOM 上......所以您的代码将如下所示:

var EC = protractor.ExpectedConditions;
// Waits for the element with id 'topic_0' to be visible on the dom.
browser.wait(EC.visibilityOf($('#topic_0')), 5000);
element(by.css('#topic_0')).click();

请注意,当使用 CSS 选择器作为定位器时,您可以使用快捷方式 $() 表示法

$('my-css');
// Is the same as:
element(by.css('my-css'));
于 2020-03-03T16:10:18.607 回答