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"}
findElement WebDriverElement, , , .
findElement
, , findElements. findElements , . , .
findElements
if (count($driver->findElements(WebDriverBy::xpath("image-e4e"))) === 0) { echo 'not found'; }
: $ driver- > findElements intstead of findElement. findElements , .
, 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.
image-e4e
if($driver->findElement(WebDriverBy::id("image-e4e")) != 0) { }
Try the above logic. I'm sure it will work for sure.