Source
xxxxxxxxxx
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\Remote\RemoteWebElement;
use Facebook\WebDriver\Exception\StaleElementReferenceException;
/**
* Base class for web page elements.
*/
abstract class CBaseElement extends RemoteWebElement {
/**
* Option that allows to disable auto reload of staled elements.
*
* @var boolean
*/
protected $reload_staled = true;
/**
* Method called when element is stalled.
* This method should be overridden to provide logic of reloading stalled elements.
*/
public abstract function reload();
/**
* Execute element action in a stale safe context.
*
* @param string $method method to be executed
* @param array $params method execution params
*
* @return mixed
*/
private function executeStaleSafe($method, $params = []) {
try {
return call_user_func_array([parent::class, $method], $params);
}
catch (StaleElementReferenceException $exception) {
if (!$this->reload_staled) {
throw $exception;
}
$this->reload();
}
return call_user_func_array([parent::class, $method], $params);
}
/**
* Check if element is in stalled state.
*
* @return boolean
*/
public function isStalled() {
try {
parent::isEnabled();
}
catch (StaleElementReferenceException $exception) {
return true;
}
catch (Exception $exception) {
// Code is not missing here.
}
return false;
}
/**
* Alias for sendKeys.
* @see RemoteWebElement::sendKeys
*
* @param string $text
*
* @return $this
*/
public function type($text) {
return $this->sendKeys($text);
}