【问题标题】:Undefined property: stdClass::$ELEMENT未定义的属性:stdClass::$ELEMENT
【发布时间】:2020-02-18 01:17:21
【问题描述】:

我在 youtube 上找到了一个关于在 windows 中使用 php 的 selenium webdriver 的教程。我已经设置了 xampp,安装了一些依赖项,以及 jar 文件和 geckodriver 之类的其他依赖项。当我执行php代码时。我得到了这个错误。

Notice: Undefined property: stdClass::$ELEMENT in C:\xampp\htdocs\sample1\phpwebdriver\WebElement.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 天。我不知道该怎么办。提前感谢,如果有人有答案,真的很感激。

【问题讨论】:

  • 这是文件:WebElement.php 吗?

标签: php webdriver geckodriver


【解决方案1】:

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

转到里面的 phpwebdriver 文件夹并找到文件 webElement.php。 在第 28 行中,您将获得代码:-

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

将此行替换为:-

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

然后再次运行运行您的测试文件。错误将得到解决。

【讨论】:

    【解决方案2】:

    如果你用这个WebDriver应该没问题。

    我认为你不能使用 require_once = phpwebdriver/WebDriver,因为它应该被 vendor/autoload.php 替换,就像在 this original example 中一样。

    我也建议使用这个。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-29
      • 1970-01-01
      • 2016-04-20
      • 2019-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多