我可以点击一个带硒的模态上的按钮吗

Can I click on a button on a modal with selenium?

本文关键字:模态 按钮 一个 我可以      更新时间:2024-02-24

我正试图将chimpjs与cucumber和selenium一起使用来自动登录,但我们目前是通过模式登录的。目前,所有尝试点击该模式上的登录按钮都会导致相同的错误:

 Error: unknown error: Element is not clickable at point (764, 42). Other element would receive the click: <div class="login-overlay " style="display: block; opacity: 0.969096;">...</div>

以下是我为硒所采取的步骤。在输入用户名或密码之前,我正在等待模态出现,但当我尝试单击登录按钮时,它在我身上失败了。

module.exports = function() {
  this.Given(/^I am on the website homepage$/, function () {
    client.url('example.com');
  });
  this.When(/^I click the login button$/, function () {
    client.click('.navbar__link--login');
  });
  this.Then(/^I see the login screen$/, function () {
    client.waitForExist('.login-overlay');
  });
  this.Then(/^I enter my username in the email field$/, function () {
    client.setValue('#username', 'myemail@email.com');
  });
  this.Then(/^I enter my password in the password field$/, function () {
    client.setValue('#password', 'myemail@email.com');
  });
  this.Then(/^And I click the login button$/, function () {
    client.click('.login-btn');
  });
};

目前,除了最后一步,一切都通过了。这是因为我们使用模态登录吗?或者有没有办法点击硒模式的按钮?还是我错过了一个非常明显的步骤?

解决方案:我找到了解决方案,我无法单击元素,但我可以通过client.submitForm(selector)选项提交表单。这样做似乎解决了问题,我能够通过最后一步。为了可读性,我还将最后一步改为"我提交登录表单"。您可以在此处查看有关表单提交选项的更多信息:http://webdriver.io/api/action/submitForm.html

听起来控件顶部有一个"login overlay"元素。

作为一种变通方法,使其不可见:

client.execute("arguments[0].style.display = 'none';", client.element('.login-btn'));

未经测试。