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.

_Keypress to the end of the page

Fabrice BFabrice B Members
edited November -1 in Sahi - Open Source
Hi all,

I've a problem, i use key press enter on a textbox and it works fine

_keyPress(_textbox("" , _under(_div("editableLabel-label"))), [13,13]); <== OK


but now i want to go at the end a page. i found the element, i click it but when i want to press "end" : nothing happens. (_keyPress(_div("newsDoc-content-new"), [79,79]);)

maybe it's not the right code, Maybe it is not the right method...

It is right to use keypress for this action ?

Where can i find codes for _keypress() of sahi?

Thx

Regard

Fabrice

Comments

  • Hi,

    to update my message, i tried http://sahi.co.in/demo/eventSequence.htm, and i found the code : it's 35. But it still not work with keypress
    t1:keypress; e.keyCode=35; e.charCode=0
    t1:keyup; e.keyCode=35; e.charCode=0
    t1:blur; e.keyCode=undefined; e.charCode=undefined
    _focus(_div("newsDoc-content-new"));
    _keyPress(_div("newsDoc-content-new"), [35,35]);

    Thank you

    Fabrice
  • Hi Fabrice B,

    _keyPress(_textbox("" , _under(_div("editableLabel-label"))), [13,13]); <== OK worked because an event is attached to the textbox.

    You can perform keyPress on _div("newsDoc-content-new") only if an event is attached to it.

    To find more examples you can navigate to <sahi-home>/userdata/scripts/demo/keyPress.sah.

    Regards
    Sumitra
  • Hi Sumitra,

    Thanks for your answer. In keyPress.sah, all examples are plugged on a textbox, that is to say with an event.

    My actual problem is simulate a keypress (in my case "end") on a simple page, without event.

    How can i do that in Sahi ?

    Thank you

    Fabrice
  • Hi Fabrice B,

    Since "end" on a simple page is without an event, its not possible to do keyPress on it.

    Regards
    Sumitra
  • hi Sumitra

    HARG.... thank you

    Any idea to realise this action ? another method than Keypress, maybe

    I've a _div with scroll vertical bar, and when it opens i'm on the top of it : i just want to go at the end of it...

    Thank you

    Fabrice
  • Hi Fabrice B,

    You can use:
    var $nHeight = _eval("document.body.scrollHeight");
            var $nTop = _eval("document.body.scrollTop");
            var $nCHeight = _eval("document.body.clientHeight");
            _alert($nHeight + " " + $nTop + " " + $nCHeight);
            if (_condition($nHeight > ($nTop + $nCHeight))) {
            //bar present       
            }else{
                    //bar  not present
            }
    

    OR

    You can use:

    _call(window.scrollTo(0, 1200));

    Regards
    Sumitra
  • ok i'll go to try that whenever I can

    thank you so

    Fabrice
  • Hi all,

    Sorry for the delay, i tried _call(window.scrollTo(0, 1200)); : it works on lot of page, but i give you a site (site of my company) where i can't go at the end of the page

    if you have an idea... Thank you so

    _navigateTo("http://www.google.fr/webhp?hl=fr&tab=ww";);
    _click(_textbox("q"));
    _setValue(_textbox("q"), "France");
    _call(window.scrollTo(0, 1200));
    _alert("Ok Google page is at the end");

    _wait(2000);
    _navigateTo("http://www.arisem.com/index.php?page=evenements";);
    _wait(2000);

    _highlight(_div("txt_rubrique_scroll"));
    _alert("scrollHeight = " + _div("txt_rubrique_scroll").scrollHeight);
    _call(window.scrollTo(0, 1200));
    _call(_div("txt_rubrique_scroll").scrollTo(0, 4000));
    _alert("NOTOk the _div-scroll is still on top");
  • narayannarayan Administrators
    Use:

    _call(_div("txt_rubrique_scroll").scrollTop = _div("txt_rubrique_scroll").scrollHeight);

    to scroll down non window objects.

    Regards,
    Narayan
  • Hi Naryan,

    Thank you so ... it works

    regards

    Fabrice
This discussion has been closed.