Mink/Goutte How to check checkbox without attribute in Goutte?

前端 未结 2 561
别那么骄傲
别那么骄傲 2020-12-22 06:16

I apologize in advance but I am very beginner. I try to check checkbox without id or name.

相关标签:
2条回答
  • 2020-12-22 06:35

    Try to use click and also add Exception in case that the element is not found.

    Example: If the element is not found, the find method will return null and you will try to click on null, this will throw a fatal exception and your suite will stop.

    if you add an exception only the current scenario will fail and the suite will continue to execute.

    public function iClick($selector, $locator){
        $node = $this->getSession()->getPage()->find($selector, $locator);
    
        if($node === null){
            throw new Exception("Element $locator not found!");
        }else{
            $node->click();
        }
    }
    

    If the element is type checkbox and you want to do a check, no matter if is checked or not, you can create a method that uses check() instead of click()

    0 讨论(0)
  • 2020-12-22 06:43

    You have to use the method checkOption($option) of MinkContext (in Behat/MinkExtension that you must install via Composer).

    MinkContext is installed by default in Behat environment.

    MinkContext.php

    Hope it works.

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