【问题标题】:Clicking a Date-Calendar with Codeception使用 Codeception 单击日期日历
【发布时间】:2018-02-07 08:44:24
【问题描述】:

用户第一次点击到达日期,第二次点击离开日期。

这是我的代码。

//Change Arriving Date
    $dateFrom = date( 'j'); // Get today's Day
    $dateTo = date('j', strtotime("+2 day")); // Add x Days from now

    $I->click('.js-date-view');
    $I->waitForElement('.mod-3rd-level-navi__anchor');
    $I->click($dateFrom);
    $I->wait(1);
    $I->moveMouseOver($dateTo);
    $I->click($dateTo);
    $I->wait(1);

    //Submit
    $I->click('.js-send-form.btn-primary');

测试在$dateTO 失败,但在$dateFrom 没有失败。 Baiscly 它不想点击离开日期。

步骤在 12 点失败

 12. $I->moveMouseOver("11") at tests/acceptance/../../changeDetailsCest.php:42
 11. $I->wait(1) at tests/acceptance/.../.../changeDetailsCest.php:41
 10. $I->click("7") at tests/acceptance/.../.../changeDetailsCest.php:40
 9. $I->waitForElement(".mod-3rd-level-navi__anchor") at tests/acceptance/.../.../changeDetailsCest.php:39
 8. $I->click(".js-date-view") at tests/acceptance/.../.../changeDetailsCest.php:38
 7. $I->wait(1) at tests/acceptance/.../.../changeDetailsCest.php:32

错误

[MalformedLocatorException] CSS or XPath locator is malformed: 11

【问题讨论】:

  • 它是如何失败的?
  • @Naktibalda 我收到 shell 中的 codepcetion 引发的错误。如果我使用 -vvv 运行我的测试,它会说它点击了“今天的日期”,但在 x 天内失败了。这就是它如此令人困惑的原因。
  • 准确的 Codeception 错误和 Selenium 的相关输出将提高您获得答案的机会。
  • 编辑帖子

标签: php selenium codeception


【解决方案1】:

moveMouseOver 采用与click 不同的参数。

click 尝试按文本查找元素 -

如果给定了一个模糊定位器,则页面将搜索与定位器字符串匹配的按钮、链接或图像。对于按钮,搜索“值”属性、“名称”属性和内部文本。对于链接,搜索链接文本。对于图像,搜索任何父链接的“alt”属性和内部文本。

moveMouseOver 不按文本搜索,您必须为其提供有效的 CSS 或 XPath 选择器。 示例:$I->moveMouseOver('#date-11')

如果你得到它的工作,你可以使用clickWithLeftButton 方法而不是moveMouseOver + click 的组合。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-08
    • 2020-02-10
    • 2014-12-25
    • 2022-08-14
    • 1970-01-01
    相关资源
    最近更新 更多