XPath Error in Mink: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type

brianrhea

I'm using Mink and the Selenium2 Driver with Behat to run some acceptance tests and for the most part, everything is going well.

However, I'm trying to target an element based on a data-* attribute with XPath, and the test chokes on it.

I've used XPathHelper and FirePath and my XPath checks out in both of those extensions:

//html//@data-search-id='images'

That appears to target the correct element.

However, when I add the following to FeatureContext.php

$el = $this->getSession()->getPage()->find('xpath', $this->getSession()->getSelectorsHandler()->selectorToXpath('xpath', "//@data-search-id='images'"));
$el->click();

I get the following error from Behat:

invalid selector: Unable to locate an element with the xpath expression
//html//@data-search-id='images' because of the following error:

TypeError: Failed to execute 'evaluate' on 'Document':
The result is not a node set, and therefore cannot be converted
to the desired type.
Jens Erat

Your XPath expression is a totally valid expression – it will find all @data-search-id attributes and return true if one of them is 'images', otherwise false.

But you want to click an item, and obviously clicking a boolean value is rather difficult. Query for the item fulfilling the condition instead (thus, move the comparison into a predicate):

//html//*[@data-search-id='images']

Additionally, I'd remove the //html. The HTML node must be the root node anyway, so /html would have been fine (no reason for searching it in all subtree). As you're searching for an arbitrary descendent of it, and this will not be the root node (as <html/> is), omitting it completely does not change the meaning of the XPath expression.

//*[@data-search-id='images']

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SyntaxError: Failed to execute 'evaluate' on 'Document' error passing parameter as xpath?

From Dev

Getting an error: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Error: Failed to execute 'insertBefore' on 'Node'

From Dev

Leaflet.markercluster onclick error - Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error on append tr to a table

From Dev

Javascript error: Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Generic type error: Instance cannot be converted to its own type?

From Dev

Excel dates cannot be converted to desired format

From Dev

Random effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'

From Dev

Random effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'

From Dev

Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'

From Dev

typeError: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node Polymer

From Dev

Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

From Dev

Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. in Chrome

From Dev

JAVAFX error incompatible types: FXMLLoader cannot be converted to node

From Dev

Failed to execute 'write' on 'Document' error in loading angular google map

From Dev

error Nil default argument value of cannot be converted to type 'NSLayoutFormatOptions'

From Dev

json error value of type string cannot be converted to jsonobject

From Dev

json error value of type string cannot be converted to jsonobject

From Dev

Cannot get if to evaluate the result of $? correctly

From Dev

Error in xpath compile evaluate query

From Dev

Class<Result> cannot be converted to Class<Result<Integer>>

From Dev

polymer breaks document.evaluate (xpath)

From Dev

document.evaluate to evaluate Xpath on HTML produced in-browser by XSLT

From Dev

failed to execute appendchild on node

From Dev

Nintex for O365: XPath query is invalid. Expression must evaluate to a node-set

From Dev

EchoSign - Failed to execute 'write' on 'Document'?

From Dev

Failed processing format-parameters; Python 'tuple' cannot be converted to a MySQL type

Related Related

  1. 1

    SyntaxError: Failed to execute 'evaluate' on 'Document' error passing parameter as xpath?

  2. 2

    Getting an error: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  3. 3

    Error: Failed to execute 'insertBefore' on 'Node'

  4. 4

    Leaflet.markercluster onclick error - Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  5. 5

    Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node' error on append tr to a table

  6. 6

    Javascript error: Uncaught TypeError: Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

  7. 7

    Generic type error: Instance cannot be converted to its own type?

  8. 8

    Excel dates cannot be converted to desired format

  9. 9

    Random effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'

  10. 10

    Random effect predictions from gamm model error: cannot evaluate groups for desired levels on 'newdata'

  11. 11

    Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'

  12. 12

    Uncaught TypeError: Failed to execute 'insertBefore' on 'Node': parameter 1 is not of type 'Node'

  13. 13

    typeError: Failed to execute 'contains' on 'Node': parameter 1 is not of type 'Node Polymer

  14. 14

    Failed to execute 'removeChild' on 'Node': parameter 1 is not of type 'Node'

  15. 15

    Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'. in Chrome

  16. 16

    JAVAFX error incompatible types: FXMLLoader cannot be converted to node

  17. 17

    Failed to execute 'write' on 'Document' error in loading angular google map

  18. 18

    error Nil default argument value of cannot be converted to type 'NSLayoutFormatOptions'

  19. 19

    json error value of type string cannot be converted to jsonobject

  20. 20

    json error value of type string cannot be converted to jsonobject

  21. 21

    Cannot get if to evaluate the result of $? correctly

  22. 22

    Error in xpath compile evaluate query

  23. 23

    Class<Result> cannot be converted to Class<Result<Integer>>

  24. 24

    polymer breaks document.evaluate (xpath)

  25. 25

    document.evaluate to evaluate Xpath on HTML produced in-browser by XSLT

  26. 26

    failed to execute appendchild on node

  27. 27

    Nintex for O365: XPath query is invalid. Expression must evaluate to a node-set

  28. 28

    EchoSign - Failed to execute 'write' on 'Document'?

  29. 29

    Failed processing format-parameters; Python 'tuple' cannot be converted to a MySQL type

HotTag

Archive