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.

Java Syntax howto for sahi script _position

hoijahoija Members
edited October 2012 in Sahi - Open Source
Hi,

I found:
var $heightEl1 = _position($element1)[1];
in an other forumpost. It gets you the value of the y coordinate of the element.

It's working for me like that:
browser.execute("_sahi._alert(_sahi._position(_sahi._span('belegärztliche Behandlung'))[1])");
It shows 425 in a messagebox.

The point is: I'm working with sahi from within Twist with the Java Wrapper of sahi and I need that value in a variable in Java, not only in an sahi messagebox.
browser.execute itself returns void.

I could replace:
_sahi._position(_sahi._span('belegärztliche Behandlung'))[1])
with
browser.position( browser.span( "belegärztliche Behandlung" ) ) + "[1])"

so the call now is

browser.execute("_sahi._alert(" + browser.position( browser.span( "belegärztliche Behandlung" ) ) + "[1])");
It also shows 425 in a message box. This far it is working.

But I did not manage to get to the 425 via "only" Java with browser.position( browser.span( "belegärztliche Behandlung" ) - so without sahi alert. Javadocs say, position returns an array, for example [100, 180]. In javadoc under returns it also says: a stub representing the element.

My several approaches only return: "undefined" or "_sahi._position(_sahi._span("belegärztliche Behandlung"))".

For example
ElementStub a = browser.position( browser.span( "belegärztliche Behandlung" ) );
System.out.println("Test: " + a );
gives
Test: _sahi._position(_sahi._span("belegärztliche Behandlung"))

or
System.out.println("Test: " + a.value() );
gives
Test: undefined

Any ideas?

This is on Windows 7 with Firefox 14.01 and sahi (within Twist). The sahi controller from within Twist does not show the sahi version number, but I found this: com.thoughtworks.twist.driver.sahi_3.0.0.12641-3bffc171c71291.

Thank you!

Comments

  • narayannarayan Administrators
    Hi,

    What you need is the browser.fetch() method.

    String yStr = browser.fetch("_sahi._position(_sahi._span('belegärztliche Behandlung'))[1])");

    Regards,
    Narayan
  • Hi, Narayan,

    You made my day! It works!

    String yStr = browser.fetch("_sahi._position(_sahi._span('belegärztliche Behandlung'))[1]");
    System.out.print( "Test: " + yStr );

    gives

    Test: 425

    Thank you very much :-)
Sign In or Register to comment.