Unexpected, to me, return value from javascript in Robot Framework. Why?












1















When I execute this Javascript in Robot Framework



${locator}    Execute JavaScript    return document.activeElement
log ${locator}


the log looks something like this:



KEYWORD BuiltIn . Log ${Locator}
Documentation:
Logs the given message with the given level.

Start / End / Elapsed: 20181120 12:14:37.008 / 20181120 12:14:37.008 / 00:00:00.000
12:14:37.008 INFO <selenium.webdriver.remote.webelement.WebElement (session="b1f6da572666aa24004769a4ab3a2171", element="0.7758470428784936-13")>


However, when I execute the same code in the console of Chrome the result might look something like this:



input#login_field.form-control.input-block


Why does the RF/JS-combo return such a weird format/value? I need a CSS-id or similar.










share|improve this question



























    1















    When I execute this Javascript in Robot Framework



    ${locator}    Execute JavaScript    return document.activeElement
    log ${locator}


    the log looks something like this:



    KEYWORD BuiltIn . Log ${Locator}
    Documentation:
    Logs the given message with the given level.

    Start / End / Elapsed: 20181120 12:14:37.008 / 20181120 12:14:37.008 / 00:00:00.000
    12:14:37.008 INFO <selenium.webdriver.remote.webelement.WebElement (session="b1f6da572666aa24004769a4ab3a2171", element="0.7758470428784936-13")>


    However, when I execute the same code in the console of Chrome the result might look something like this:



    input#login_field.form-control.input-block


    Why does the RF/JS-combo return such a weird format/value? I need a CSS-id or similar.










    share|improve this question

























      1












      1








      1








      When I execute this Javascript in Robot Framework



      ${locator}    Execute JavaScript    return document.activeElement
      log ${locator}


      the log looks something like this:



      KEYWORD BuiltIn . Log ${Locator}
      Documentation:
      Logs the given message with the given level.

      Start / End / Elapsed: 20181120 12:14:37.008 / 20181120 12:14:37.008 / 00:00:00.000
      12:14:37.008 INFO <selenium.webdriver.remote.webelement.WebElement (session="b1f6da572666aa24004769a4ab3a2171", element="0.7758470428784936-13")>


      However, when I execute the same code in the console of Chrome the result might look something like this:



      input#login_field.form-control.input-block


      Why does the RF/JS-combo return such a weird format/value? I need a CSS-id or similar.










      share|improve this question














      When I execute this Javascript in Robot Framework



      ${locator}    Execute JavaScript    return document.activeElement
      log ${locator}


      the log looks something like this:



      KEYWORD BuiltIn . Log ${Locator}
      Documentation:
      Logs the given message with the given level.

      Start / End / Elapsed: 20181120 12:14:37.008 / 20181120 12:14:37.008 / 00:00:00.000
      12:14:37.008 INFO <selenium.webdriver.remote.webelement.WebElement (session="b1f6da572666aa24004769a4ab3a2171", element="0.7758470428784936-13")>


      However, when I execute the same code in the console of Chrome the result might look something like this:



      input#login_field.form-control.input-block


      Why does the RF/JS-combo return such a weird format/value? I need a CSS-id or similar.







      javascript google-chrome console robotframework






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 13:48









      henstihensti

      1605




      1605
























          1 Answer
          1






          active

          oldest

          votes


















          2














          In essence this is what a WebElement object looks like. What Google does to represent that object value is to pick certain attributes that are human readable/recognizable and display those. There is (complex) logic behind this to show the unique CSS locator for a particular element.



          An element is generally not used by Robot Framework but is can be. In the below example it is used instead of a locator:



          *** Settings ***
          Library SeleniumLibrary
          Suite Teardown Close All Browsers

          *** Test Cases ***
          Get WebElement Name
          Open Browser http://google.com chrome
          ${WebElement} Execute Javascript return document.activeElement
          ${name} Get Element Attribute ${WebElement} name
          Log ${name}


          Resulting in:



          Starting test: Folder.Webdriver.Get WebElement Name
          20181120 18:58:55.406 : INFO : Opening browser 'chrome' to base url 'http://google.com'.
          20181120 18:58:59.499 : INFO : Executing JavaScript:
          return document.activeElement
          20181120 18:58:59.511 : INFO : ${WebElement} = <selenium.webdriver.remote.webelement.WebElement (session="c3648128649f6ffea907d36a6533e3fc", element="0.6417788615033906-1")>
          20181120 18:58:59.527 : INFO : ${name} = q
          20181120 18:58:59.527 : INFO : q
          Ending test: Folder.Webdriver.Get WebElement Name


          However the same could be achieved with only a small alteration of the javascript:



          Get WebElement Name
          Open Browser http://google.com chrome
          ${name} Execute Javascript return document.activeElement.name





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394475%2funexpected-to-me-return-value-from-javascript-in-robot-framework-why%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2














            In essence this is what a WebElement object looks like. What Google does to represent that object value is to pick certain attributes that are human readable/recognizable and display those. There is (complex) logic behind this to show the unique CSS locator for a particular element.



            An element is generally not used by Robot Framework but is can be. In the below example it is used instead of a locator:



            *** Settings ***
            Library SeleniumLibrary
            Suite Teardown Close All Browsers

            *** Test Cases ***
            Get WebElement Name
            Open Browser http://google.com chrome
            ${WebElement} Execute Javascript return document.activeElement
            ${name} Get Element Attribute ${WebElement} name
            Log ${name}


            Resulting in:



            Starting test: Folder.Webdriver.Get WebElement Name
            20181120 18:58:55.406 : INFO : Opening browser 'chrome' to base url 'http://google.com'.
            20181120 18:58:59.499 : INFO : Executing JavaScript:
            return document.activeElement
            20181120 18:58:59.511 : INFO : ${WebElement} = <selenium.webdriver.remote.webelement.WebElement (session="c3648128649f6ffea907d36a6533e3fc", element="0.6417788615033906-1")>
            20181120 18:58:59.527 : INFO : ${name} = q
            20181120 18:58:59.527 : INFO : q
            Ending test: Folder.Webdriver.Get WebElement Name


            However the same could be achieved with only a small alteration of the javascript:



            Get WebElement Name
            Open Browser http://google.com chrome
            ${name} Execute Javascript return document.activeElement.name





            share|improve this answer




























              2














              In essence this is what a WebElement object looks like. What Google does to represent that object value is to pick certain attributes that are human readable/recognizable and display those. There is (complex) logic behind this to show the unique CSS locator for a particular element.



              An element is generally not used by Robot Framework but is can be. In the below example it is used instead of a locator:



              *** Settings ***
              Library SeleniumLibrary
              Suite Teardown Close All Browsers

              *** Test Cases ***
              Get WebElement Name
              Open Browser http://google.com chrome
              ${WebElement} Execute Javascript return document.activeElement
              ${name} Get Element Attribute ${WebElement} name
              Log ${name}


              Resulting in:



              Starting test: Folder.Webdriver.Get WebElement Name
              20181120 18:58:55.406 : INFO : Opening browser 'chrome' to base url 'http://google.com'.
              20181120 18:58:59.499 : INFO : Executing JavaScript:
              return document.activeElement
              20181120 18:58:59.511 : INFO : ${WebElement} = <selenium.webdriver.remote.webelement.WebElement (session="c3648128649f6ffea907d36a6533e3fc", element="0.6417788615033906-1")>
              20181120 18:58:59.527 : INFO : ${name} = q
              20181120 18:58:59.527 : INFO : q
              Ending test: Folder.Webdriver.Get WebElement Name


              However the same could be achieved with only a small alteration of the javascript:



              Get WebElement Name
              Open Browser http://google.com chrome
              ${name} Execute Javascript return document.activeElement.name





              share|improve this answer


























                2












                2








                2







                In essence this is what a WebElement object looks like. What Google does to represent that object value is to pick certain attributes that are human readable/recognizable and display those. There is (complex) logic behind this to show the unique CSS locator for a particular element.



                An element is generally not used by Robot Framework but is can be. In the below example it is used instead of a locator:



                *** Settings ***
                Library SeleniumLibrary
                Suite Teardown Close All Browsers

                *** Test Cases ***
                Get WebElement Name
                Open Browser http://google.com chrome
                ${WebElement} Execute Javascript return document.activeElement
                ${name} Get Element Attribute ${WebElement} name
                Log ${name}


                Resulting in:



                Starting test: Folder.Webdriver.Get WebElement Name
                20181120 18:58:55.406 : INFO : Opening browser 'chrome' to base url 'http://google.com'.
                20181120 18:58:59.499 : INFO : Executing JavaScript:
                return document.activeElement
                20181120 18:58:59.511 : INFO : ${WebElement} = <selenium.webdriver.remote.webelement.WebElement (session="c3648128649f6ffea907d36a6533e3fc", element="0.6417788615033906-1")>
                20181120 18:58:59.527 : INFO : ${name} = q
                20181120 18:58:59.527 : INFO : q
                Ending test: Folder.Webdriver.Get WebElement Name


                However the same could be achieved with only a small alteration of the javascript:



                Get WebElement Name
                Open Browser http://google.com chrome
                ${name} Execute Javascript return document.activeElement.name





                share|improve this answer













                In essence this is what a WebElement object looks like. What Google does to represent that object value is to pick certain attributes that are human readable/recognizable and display those. There is (complex) logic behind this to show the unique CSS locator for a particular element.



                An element is generally not used by Robot Framework but is can be. In the below example it is used instead of a locator:



                *** Settings ***
                Library SeleniumLibrary
                Suite Teardown Close All Browsers

                *** Test Cases ***
                Get WebElement Name
                Open Browser http://google.com chrome
                ${WebElement} Execute Javascript return document.activeElement
                ${name} Get Element Attribute ${WebElement} name
                Log ${name}


                Resulting in:



                Starting test: Folder.Webdriver.Get WebElement Name
                20181120 18:58:55.406 : INFO : Opening browser 'chrome' to base url 'http://google.com'.
                20181120 18:58:59.499 : INFO : Executing JavaScript:
                return document.activeElement
                20181120 18:58:59.511 : INFO : ${WebElement} = <selenium.webdriver.remote.webelement.WebElement (session="c3648128649f6ffea907d36a6533e3fc", element="0.6417788615033906-1")>
                20181120 18:58:59.527 : INFO : ${name} = q
                20181120 18:58:59.527 : INFO : q
                Ending test: Folder.Webdriver.Get WebElement Name


                However the same could be achieved with only a small alteration of the javascript:



                Get WebElement Name
                Open Browser http://google.com chrome
                ${name} Execute Javascript return document.activeElement.name






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 20 '18 at 18:03









                A. KootstraA. Kootstra

                4,49221032




                4,49221032
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53394475%2funexpected-to-me-return-value-from-javascript-in-robot-framework-why%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

                    ComboBox Display Member on multiple fields

                    Is it possible to collect Nectar points via Trainline?