Check element exists using PHP Selenium 2 Webdriver?

I'm trying to check if an element exists on a CSS page using Selenium 2. Anyone have examples using PHP Selenium Webdriver Facebook wrapper?

I tried the code below:

  if($driver->findElement(WebDriverBy::xpath("image-e4e")) != 0)
  {

                }

but gives me this error:

Fatal error: throw exception "NoSuchElementWebDriverError" with message 'Could not find element: {"Method": "XPath", "selector": "e4e image"}

+4
source share
4 answers

findElement WebDriverElement, , , .

, , findElements. findElements , . , .

if (count($driver->findElements(WebDriverBy::xpath("image-e4e"))) === 0) {
  echo 'not found';
}
+10

: $ driver- > findElements intstead of findElement. findElements , .

+1

, xpath .

xpath, seletor

//*[@id='image-e4e']

, CSS Selectors.

WebDriverBy::cssSelector("#image-e4e")

This of course assumes an identifier image-e4e. The reason your xpath was failing was because xpath was trying to find an immediate child with a tag name image-e4e. you want to parse all pom for an element with attribute equal to image-e4e. I do not know this identifier or name.

0
source
if($driver->findElement(WebDriverBy::id("image-e4e")) != 0)
{

}

Try the above logic. I'm sure it will work for sure.

-1
source

All Articles