未定义的属性:标准类::$ELEMENT



我在youtube上找到了一个关于使用php的Windows中的Selenium网络驱动程序的教程。我已经设置了 xampp,安装了一些依赖项,以及其他像 jar 文件和壁虎驱动程序一样的依赖项。当我执行 php 代码时。我收到此错误。

Notice: Undefined property: stdClass::$ELEMENT in C:xampphtdocssample1phpwebdriverWebElement.php on line 28

这是我的 php 代码:

<?php
/*
Copyright 2011 3e software house & interactive agency
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

require_once "phpwebdriver/WebDriver.php";
$webdriver = new WebDriver("localhost", "4444");
$webdriver->connect("firefox");                            
$webdriver->get("http://google.com");
$element = $webdriver->findElementBy(LocatorStrategy::name, "q");
if ($element) {
$element->sendKeys(array("hello" ) );
$element->submit();
}
?>

请有人帮忙,我已经为这个错误工作了 2 天。我不知道该怎么办。提前感谢,如果有人有答案,真的很感激。

我有同样的问题,但我通过调试代码解决了这个错误。

转到内部的phpwebdriver文件夹并找到文件webElement.php。 内联数字 28 您将获得代码:-

parent::__construct($root . "/element/" . $element->ELEMENT);

将此行替换为:-

foreach ($element as $ele){
parent::__construct($root . "/element/" . $ele);
}

并再次运行运行测试文件。错误将得到解决。

如果你使用这个网络驱动程序,它应该没问题。

我认为您不能使用 require_once =phpwebdriver/WebDriver因为它应该像这个原始示例中一样替换为vendor/autoload.php

我也建议使用这个。

最新更新