【问题标题】:PHPUnit + Selenium `InvalidArgumentException: Element not found`PHPUnit + Selenium`InvalidArgumentException:找不到元素`
【发布时间】:2020-03-25 15:21:44
【问题描述】:

按照here 的示例,尝试实现一些 Selenium 测试。

测试类代码:

class StackoverflowTest extends \PHPUnit_Extensions_Selenium2TestCase
{
    protected function setUp(): void
    {
        $this->setHost('localhost');
        $this->setPort(4444);
        $this->setBrowserUrl('https://stackoverflow.com/');
        $this->setBrowser('chrome');

        parent::setUp();
    }

    public function onNotSuccessfulTest(Throwable $e): void
    {
        $filedata = $this->currentScreenshot();
        $file     = __DIR__ . '/' . time() . '.png';
        file_put_contents($file, $filedata);

        parent::onNotSuccessfulTest($e);
    }

    /**
     * @test
     */
    public function visit_home_page_case_success()
    {
        $this->url('/');
        dump($this->title());
        dd($this->byTag('body')->text()); //line 35
    }
}

控制台输出:

...

"Stack Overflow - Where Developers Learn, Share, & Build Careers"

...

There was 1 error: 1) ...\StackoverflowTest::visit_home_page_case_success InvalidArgumentException: Element not found.

...

.../StackoverflowTest.php:35

...

截图:

出了什么问题以及如何与页面元素进行交互?

重复here

【问题讨论】:

    标签: php selenium selenium-webdriver phpunit


    【解决方案1】:

    回复here:

    很遗憾 phpunit-selenium 还不支持 W3C 模式,你可以通过以下方式强制它使用非 w3c 模式:

    $this->setDesiredCapabilities(['chromeOptions' => ['w3c' => false]]); 
    

    【讨论】:

      猜你喜欢
      • 2019-12-19
      • 2017-04-14
      • 2019-01-02
      • 2021-03-14
      • 1970-01-01
      相关资源
      最近更新 更多