18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Invalid Xpath message when using Behat/Mink

novanova Members
edited April 2014 in Sahi - Open Source
Hi

I am using Behat/Mink + Sahi, and I am trying to write regression tests for an application built by a third-party vendor so I have no control over the HTML structure. The pages have numerous elements that are dynamically generated and numerous buttons with no text (image based). Some of these buttons fulfill the function of activating a drop down box for field (autocomplete lists). These buttons have no unique ids or content. I am trying to write a generic If I click on the button near "some text" test step. I know Sahi has 'near' and 'under' functionality but these are not available in Behat/Mink, what I have available are either Xpaths, or the behat/mink 'find' functionality.

The findbutton functionality requires a button identifier, so I can't find just a 'button', so I am trying to use Xpaths, looking at the scope of the text close to the button. So I first find the text, then I look at the xpath definition of the text to search for the button in its scope, and if I don't find the button, I move to the parent element, extract its xpath and look for a button in its scope.

It looks as if Sahi has a problem with the format of some of these Xpaths. I get the following error:
Failed to execute 'evaluate' on 'Document': The string '(//html//span[text()='Cost center'][1]/..[1]//button)[1]' is not a valid XPath

and it looks as if it is generated in Sahi itself:
at Sahi._byXPath (https:/thedomain.com/_s_/spr/concat.js:1601:16)
at eval (eval at <anonymous> (https://thedomain.com/_s_/spr/concat.js:3480:14), <anonymous>:3:18)
at eval (eval at <anonymous> (https://thedomain.com/_s_/spr/concat.js:3480:14), <anonymous>:5:3)
at Sahi.ex (https://thedomain.com/_s_/spr/concat.js:3480:9)

When I test the Xpath with Firepath it does not show a format error.

I KNOW that Sahi does not recommend the use of Xpaths, but I cannot really think of another way of doing this unless I bypass Mink and use Behat directly with the Sahi client since I assume I will then be able to use the built-in Sahi functionality of 'near' and 'under'? I have just started to use Behat and Mink and Sahi so this is new territory to me....

Any advice would be appreciated

thanks

Answers

  • novanova Members
    Just an update - this seems to be definitely a Sahi issue since I tried the same Xpath code with Selenium2 and it worked fine.

    Any advice on how to fix this problem?
Sign In or Register to comment.