php - PHPUnit + Selenium`InvalidArgumentException:找不到元素`
问题描述
遵循此处的示例,尝试实施一些 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
...
截屏:
出了什么问题,我该如何与页面元素进行交互?
在这里重复。
解决方案
在这里回答:
不幸的是 phpunit-selenium 还不支持 W3C 模式,你可以通过以下方式强制它使用非 w3c 模式:
$this->setDesiredCapabilities(['chromeOptions' => ['w3c' => false]]);
推荐阅读
- r - Linear mixed model confidence intervals question
- c++ - 为什么继承会强制对其他大小为零的结构进行膨胀?
- r - 在 R 中为抛物线创建函数,但不向上平移
- java - MacOS在终端运行java,VM初始化时出错
- command-line-interface - 如何使用 v3 的 nuget list 获取特定包的可用版本列表
- python - 使用 Python 将图像堆叠在一起
- python - 如果开始和结束订阅日期在 14 天内,则过滤和分组订阅者
- .net - 跨多个库共享 nuget 包中包含的类型 - 最佳实践
- mongodb - 未填充猫鼬一对多关系
- javascript - 任务完成和回调函数执行之间是否有延迟?