Answer the question
In order to leave comments, you need to log in
MISTAKE. Selenium, Facebook WebDriver, PHP. What is the problem?
Good afternoon! I'm trying to figure out with selenium.
I use: selenium-server-standalone-3.9.1 and Facebook WebDriver.
When executing this code, everything is fine. Google page opens in chrome.
<?php
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once('vendor/autoload.php');
$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities);
$driver->get('https://www.google.com/');
print 'ok';
?>
<?php
namespace Facebook\WebDriver;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebDriver;
require_once('vendor/autoload.php');
$host = 'http://localhost:4444/wd/hub';
$capabilities = DesiredCapabilities::chrome();
$driver = RemoteWebDriver::create($host, $capabilities);
$driver->get('https://www.google.com/');
$driver->findElement(WebDriverBy::xpath('*[@id="tsf"]/div[2]/div/div[3]/center/input[2]'))->sendKeys('abc')->click();
print 'ok';
?>
Fatal error: Uncaught Facebook\WebDriver\Exception\NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"*[@id="tsf"]/div[2]/ div/div[3]/center/input[2]"} (Session info: chrome=75.0.3770.80) For documentation on this error, please visit: http://seleniumhq.or...ch_element.htmlBuild info: version: '3.9.1', revision: '63f7b50', time: '2018-02-07T22:42:28.403Z' System info: host: 'OBR-PC', ip: '192.168.100.104', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_211' Driver info: driver.version: unknown in C:\xampp\htdocs\ vendor\facebook\webdriver\lib\Exception\WebDriverException.php:102 Stack trace: #0 C:\xampp\htdocs\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php(326): Facebook\WebDriver\Exception\ WebDriverException::throwException(7, 'no such element...', Array) #1 C:\xampp\htdocs\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php(547): Facebook\WebDriver\Remote\ HttpCommandExecutor->execute(Object(Facebook\WebD in [/size] C:\xampp\htdocs\vendor\facebook\webdriver\lib\Exception\WebDriverException.php on line [/size]102
Answer the question
In order to leave comments, you need to log in
Good afternoon. Everything is simple. You most likely have the wrong xpath selector.
Try instead
Write like this:
//body/*
You will get all the elements inside the body tag. And there, one step at a time, go to your element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question