【问题标题】:How do I get WebGuy->fillField for <input type="email"> in Codeception acceptance test?如何在 Codeception 验收测试中为 <input type="email"> 获取 WebGuy->fillField?
【发布时间】:2014-09-09 07:09:48
【问题描述】:

在 Codeception 中,当我有 fillField 时工作正常 &lt;input type="text" name="email"&gt; 但在&lt;input type="email" name="email"&gt; 时不起作用

我已尝试使用以下代码

$I->fillField('input[name=email]', 'user@domain.com');

还有$I->fillField('email', 'user@domain.com'); 但它不起作用。我收到以下错误。

ElementNotVisibleException:元素当前不可见

【问题讨论】:

  • 顺便说一句,我正在使用 WebDriver 和 Firefox

标签: unit-testing automation acceptance-testing codeception acceptance


【解决方案1】:

我还没有在电子邮件字段上测试过如果它不起作用,您可以选择一些解决方法,如下所示:-

(1) 使用JS

$I->executeJS('window.document.getElementsByName('email')[0].value='###value###'');

(2) 使用低级 webdriver 代码:-

$I->executeInSelenium(function (\Webdriver $webdriver) {
    $webdriver->findElement('###XPATH###')->sendKeys(###value###);
});

同样,如果您遇到任何 Codeception 特定问题,请提出here

希望对你有帮助。

【讨论】:

    【解决方案2】:

    实际上我得到了答案,现在我可以通过 XPATH 定位任何表单元素,而无需运行 executeInSelenium

    所以在 chrome/firefox 中我检查了 dom 并右键单击并复制 xpath,

    例如:
    $I-&gt;fillField('//*[@id="register-form"]/fieldset/section[3]/div/div/label/input', 'user@domain');

    它也适用于其他表单元素

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-01
      • 2016-11-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-18
      相关资源
      最近更新 更多