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.

Save an image

MarSilMarSil Members
edited November -1 in Sahi - Open Source
Hi,

I would like to save an image but I didn't find the solution. I looked for on this forum and sahi pages but with no result.

Could you help me please?

Thanks
Martin

Comments

  • SumitraSumitra Members
    Hi MarSil,

    You can add the url of the image to be downloaded in download_urls.txt (from Configure link on Sahi Dashboard).

    For example if the url of the image is "http://localhost:9999/_s_/spr/images/sahi_os_logo2.png", then add

    .*images[/]sahi_os_logo2[.]png.*

    Save, restart Sahi and check.

    Regards
    Sumitra
  • MarSilMarSil Members
    edited July 2011
    Super, it works. :) Thank you.

    And do you know if exists a way to get the file name? I tried browser.lastDownloadedFileName() but it returns me "null".

    EDIT: I want full name with hash code. Or set my own name.
  • MarSilMarSil Members
    Sorry my mistake. I didn't wait for save the file and check the name before it.

    The name is:

    String fileName = browser.sessionId() + "__" + browser.lastDownloadedFileName();
  • SumitraSumitra Members
    Hi MarSil,

    There are 2 reasons for returning null when you used browser.lastDownloadedFileName() :

    1) You might have deleted the file which you have downloaded.

    2) Sahi prefixes the downloaded file with a session id. So, browser.lastDownloadedFileName() will return the last downloaded file as long as you are working in the same session. Else, it will return null.

    You don't have to prefix a sessionId explicitly.

    For more details about the file download in Sahi:

    http://sahi.co.in/w/handle-file-downloads

    Let me know if you are able to get the file name.

    Regards
    Sumitra
  • Hii,
    can u please tell me how to store image in a variable ....
    this code is not working.

    var $image=_image("fgrp_y.gif",_leftOf(_link($grpname)));
    _log($image);
  • var x= _image("_sahi_ignore_2");
    _alert(x)

    output: HTMLImageElement

    works fine for me. At least in the Sahi Controller

    var x= _image("_sahi_ignore_2");
    _alert(JSON.stringify(_sahi.list(x)))
    "y=30;\nx=172;\nnaturalWidth=112;\nnaturalHeight=80;\ncomplete=true;\nwidth=112;\nsrc=http://sahi.example.com/_s_/spr/images/sahi_os_logo1.png;\nheight=80;\nspellcheck=true;\ncontentEditable=inherit;\nchildren={{[object HTMLCollection]}};\nchildren=[object HTMLCollection];\nouterHTML=<img id=\"_sahi_ignore_2\" selectable=\"false\" src=\"/_s_/spr/images/sahi_os_logo1.png\" style=\"border:0px;\">;\ndraggable=true;\ntabIndex=-1;\ntranslate=true;\nid=_sahi_ignore_2;\nwebkitRegionOverset=undefined;\ndataset={{[object DOMStringMap]}};\ndataset=[object DOMStringMap];\nclassList={{}};\nclassList=;\nscrollHeight=80;\nscrollWidth=112;\nclientHeight=80;\nclientWidth=112;\noffsetParent={{[object HTMLBodyElement]}};\noffsetParent=[object HTMLBodyElement];\noffsetHeight=80;\noffsetWidth=112;\noffsetTop=30;\noffsetLeft=172;\nstyle={{[object CSSStyleDeclaration]}};\nstyle=[object CSSStyleDeclaration];\ntagName=IMG;\nparentElement=http://sahi.co.in/;\nbaseURI=http://sahi.example.com/_s_/dyn/Driver_initialized;\nlocalName=img;\nnamespaceURI=http://www.w3.org/1999/xhtml;\nownerDocument={{[object HTMLDocument]}};\nownerDocument=[object HTMLDocument];\nattributes={{[object NamedNodeMap]}};\nattributes=[object NamedNodeMap];\nchildNodes={{[object NodeList]}};\nchildNodes=[object NodeList];\nparentNode=http://sahi.co.in/;\nnodeType=1;\nnodeName=IMG;\nALLOW_KEYBOARD_INPUT=1;\nELEMENT_NODE=1
    ;\nATTRIBUTE_NODE=2;\nTEXT_NODE=3;\nCDATA_SECTION_NODE=4;\nENTITY_REFERENCE_NODE=5;\nENTITY_NODE=6;\nPROCESSING_INSTRUCTION_NODE=7;\
    nCOMMENT_NODE=8;\nDOCUMENT_NODE=9;\nDOCUMENT_TYPE_NODE=10;\nDOCUMENT_FRAGMENT_NODE=11;\nNOTATION_NODE=12;\nDOCUMENT_POSITION_DISCONN
    ECTED=1;\nDOCUMENT_POSITION_PRECEDING=2;\nDOCUMENT_POSITION_FOLLOWING=4;\nDOCUMENT_POSITION_CONTAINS=8;\nDOCUMENT_POSITION_CONTAINED
    _BY=16;\nDOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=32;\n\n\n-----Functions------\n\ninsertAdjacentHTML\ninsertAdjacentText\nclick\ninsertAdjacentElement\ngetAttribute\nsetAttribute\nremoveAttribute\ngetAttributeNode\ngetElementsByTagName\ngetAttributeNS\nsetAttributeNS\nremoveAttributeNS\ngetElementsByTagNameNS\ngetAttributeNodeNS\nhasAttribute\nhasAttributeNS\nfocus\nblur\nscrollIntoView\nscrollIntoViewIfNeeded\nscrollByLines\nscrollByPages\ngetElementsByClassName\nquerySelector\nquerySelectorAll\nwebkitMatchesSelector\nremove\ngetClientRects\ngetBoundingClientRect\nwebkitGetRegionFlowRanges\nsetAttributeNode\nremoveAttributeNode\nsetAttributeNodeNS\nwebkitRequestFullScreen\nwebkitRequestFullscreen\nwebkitRequestPointerLock\ninsertBefore\nreplaceChild\nremoveChild\nappendChild\nhasChildNodes\ncloneNode\nnormalize\nisSupported\nhasAttributes\nlookupPrefix\nisDefaultNamespace\nlookupNamespaceURI\naddEventListener\nremoveEventListener\nisSameNode\nisEqualNode\ncompareDocumentPosition\ncontains\ndispatchEvent\n"
    
This discussion has been closed.