为什么我无法捕获意外警报异常?

问题描述 投票:0回答:1

我正在使用try catch块来捕获异常,我无法捕获它,因为它仍然说:

在Exception.php第155行中:

  unexpected alert open: {Alert text : The form is not complete and has not been submitted yet. There is 1 problem with your submission.}
    (Session info: chrome=73.0.3683.75)
    (Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.15.0-38-generic x86_64)

我的专题文件:

<?php

use Behat\Behat\Hook\Scope\AfterStepScope;
use Behat\Behat\Tester\Exception\PendingException;
use Behat\Behat\Context\Context;
use Behat\MinkExtension\Context\MinkContext;
use WebDriver\Exception\UnexpectedAlertOpen;
/**
 * Defines application features from the specific context.
 */
class FeatureContext extends MinkContext implements Context
{
    /**
     * Initializes context.
     *
     * Every scenario gets its own context instance.
     * You can also pass arbitrary arguments to the
     * context constructor through behat.yml.
     */
    public function __construct()
    {

    }

    /**
     * @Given I fill in the email field with :email
     */
    public function iFillInTheEmailFieldWith($email)
    {

        dump($email);
        $this->visit('/471w2222');
        $page = $this->getSession()->getPage();
        $page->find('xpath', '//*[@id="tfa_1111"]')->setValue($email);
    }


    /**
     * @When I submit the form
     */
    public function iSubmitTheForm()
    {

        try {
            $page = $this->getSession()->getPage();
            $page->find('xpath', '//*[@id="submit_button"]')->click();
        }
        catch (UnexpectedAlertOpen $e){
            dd($e->getMessage());
            $this->getSession()->getDriver()->getWebDriverSession()->accept_alert();
        }

    }

}

警报显示:

$page->find('xpath', '//*[@id="submit_button"]')->click();

执行。但它无法抓住它。为什么?

php selenium selenium-chromedriver behat mink
1个回答
1
投票

根据错误消息...

(Session info: chrome=73.0.3683.75)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.15.0-38-generic x86_64)

...主要问题是您使用的二进制文件版本之间的不兼容性如下:

  • 您正在使用chromedriver = 2.41
  • chromedriver=2.41的发行说明明确提到以下内容:

支持Chrome v67-69

  • 您正在使用chrome = 73.0
  • ChromeDriver v2.46的发行说明明确提到以下内容:

支持Chrome v71-73

因此,ChromeDriver v2.41与Chrome浏览器v73.0之间存在明显的不匹配

  • 将ChromeDriver升级到当前的ChromeDriver v2.46级别。
  • 将Chrome版本保持在Chrome v73级别之间。 (as per ChromeDriver v2.45 release notes
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目。
  • 如果您的基本Web客户端版本太旧,请将其卸载并安装最新的GA和已发布的Web客户端版本。
  • 进行系统重启。
  • 执行你的@Test
  • 始终在driver.quit()方法中调用tearDown(){}以正常关闭和销毁WebDriver和Web Client实例。
© www.soinside.com 2019 - 2024. All rights reserved.