PHP Mink/Zombie - handling hanging processes after a fatal exception?

前端 未结 2 897
隐瞒了意图╮
隐瞒了意图╮ 2020-12-22 07:46

I\'m using the PHP script with Mink+Zombie driver (install as on nodejs cannot find module 'zombie' with PHP mink) from here: PHP Mink/Zombie - page visit returns st

相关标签:
2条回答
  • 2020-12-22 08:20

    First thing to do in order to avoid fatal exceptions is to implement/use methods with proper error handling. You can create a method to check if the element is not null and if it is to throw a custom exception.

    For example in your case findField method will return null if the element is not found, in this case setValue will e used on a non-object resulting in a fatal error.

    0 讨论(0)
  • 2020-12-22 08:22

    An example of exception handling is:

    public function fillWith($locator, $text){
            $element = $this->getSession()->getPage()->find("xpath", $locator);
    
            if($element === null){
                throw new Exception("Element $locator not found");
            }else{
                $element->setValue($text);
            }
        }

    0 讨论(0)
提交回复
热议问题