none
How to press ENTER key inside <INPUT type="text"> in VBScript RRS feed

  • Question

  • Hello

    I have a website that has 1 input line and after writing inside what I want I need to press ENTER key on my keyboard to get to the next page.

    There is no "submit" or any other button on the page beside that one input line and the only way to go to the next page after putting text in the line is to press ENTER on keyboard.

    The HTML code looks like that:

    <form class="products__search my-3 mx-auto">
    <input tabindex="0" class="products__search__input form-control-lg form-control" style="color: rgb(24, 51, 63);" type="text" maxlength="100" placeholder="Search" value="" autocomplete="off">

    In order to write inside the input I use this VBScript:

    IE.document.getElementsByTagName("input").item(0).value = "This is the desire product"

    Now since there is no submit button, what command in VBScript will make it like I'm pressing ENTER (inside the text box).

    I tried to use this code: but it didn't work, I guess it's pressing ENTER but not inside the text box so nothing happen?

    Set WshShell = WScript.CreateObject("WScript.Shell")
    WshShell.SendKeys "{ENTER}"
    Thank you for your help and your time


    • Moved by Bill_Stewart Tuesday, December 11, 2018 9:11 PM This is not "research information for me and produce a custom script" forum
    Saturday, July 21, 2018 5:26 AM

All replies

  • Have you tried something like IE.document.forms(0).submit() ?
    Saturday, July 21, 2018 5:42 AM
  • Yes, I did it returned error because of the [] instead of () but even like that:

    IE.document.forms(0).submit() 

    It didn't do anything.

    Saturday, July 21, 2018 5:59 AM
  • Is this the first or only form on the page?
    Saturday, July 21, 2018 6:05 AM
  • The only <form> on the page
    Saturday, July 21, 2018 6:08 AM
  • How about this?

    IE.document.forms(0).submit

    Saturday, July 21, 2018 6:08 AM
  • To change focus (which is what enter does, You need to use "focus{}" to the next control.  Sometimes sending {TAB} will cause the focus to change.

    Ajax pages are quite difficult to automate.  Fist set "focus()" on the "input" control then assign the text then "focus" the next control.


    \_(ツ)_/

    Saturday, July 21, 2018 6:08 AM
  • How about this?

    IE.document.forms(0).submit

    Not working, it get the page stuck on loading.

    Here is inspect element of the browser along with event listeners, maybe you can understand why submit doesn't work even thought it's should. If you need me to provide any more information let me know

    https://imgur.com/a/cA4IkMx

    Would love to hear if you have any other idea or if you can direct me to the solution, thank you!
    • Edited by Day4Night Saturday, July 21, 2018 7:59 AM
    Saturday, July 21, 2018 7:51 AM
  • To change focus (which is what enter does, You need to use "focus{}" to the next control.  Sometimes sending {TAB} will cause the focus to change.

    Ajax pages are quite difficult to automate.  Fist set "focus()" on the "input" control then assign the text then "focus" the next control.


    \_(ツ)_/

    I tried, .focus() get it to focus on the input line but then when the command WshShell.SendKeys "{ENTER}" is running - it just delete the information that I added to the input, I don't understand why would ENTER do that instead of doing the same behavior when I click the ENTER on my keyboard.

    I also counted how many TABS press I need in order to focus on the input line after putting my desire search, did a loop that press that amount of TABS but again, when the command for ENTER kicks in, it just delete the information inside.

    I also tried WshShell.SendKeys "~"  with no success 

    Also now I realize that in order to use the SendKeys the IE window need to be on top of all others otherwise the key strokes not register which is not good for me.

    Would love to hear if you have any other idea or if you can direct me to the solution, thank you!

    p.s

    Take a look here if you have time, maybe it will help you help me. 

    https://imgur.com/a/cA4IkMx


    • Edited by Day4Night Saturday, July 21, 2018 8:00 AM
    Saturday, July 21, 2018 7:59 AM
  • I said nothing about using sendkeys.  Just use the focus method on the control assign the text then focus on the next control.


    \_(ツ)_/

    Saturday, July 21, 2018 8:03 AM
  • I said nothing about using sendkeys.  Just use the focus method on the control assign the text then focus on the next control.


    \_(ツ)_/

    You said focus on the input line, enter the text and then focus on the next control.

    I'm sorry but can you please explain what do you mean by "next control"? Thanks

    My code looks like that: (without the "next control")

    IE.document.getElementsByTagName("input")(0).focus()
    
    IE.document.getElementsByTagName("input").item(0).value = "This is the desire product"




    • Edited by Day4Night Saturday, July 21, 2018 8:11 AM
    Saturday, July 21, 2018 8:09 AM
  • To trigger an ajax transmission you need to change the focus which is what typing "enter" does.  What tis the next input box or button or any other control on the form?  Just get a reference to that and call the focus method on that control.

    IE.document.getElementsByTagName("input")(0).focus()
    IE.document.getElementsByTagName("input").item(0).value = "This is the desire product"
    ' assuming two input controls
    IE.document.getElementsByTagName("input")(1).focus()

    There is no guarantee any of these things can work since it is dependent on the web site design.


    \_(ツ)_/


    • Edited by jrv Saturday, July 21, 2018 8:15 AM
    Saturday, July 21, 2018 8:13 AM
  • First, thank you for taking your time to help me.

    Here is explanation about how the website looks: 

    https://i.imgur.com/J41csbU.jpg

    To the left is before I put a value in search and click ENTER to the right is after.

    I tried to use focus on every element that you see on the screen after adding a value to the input box and nothing happen.

    I think the user - Leif-Arne Helland is right and submit() is the way to go because it looks like it's waiting for that kind of event but using .submit() trying to load a new page and get the page stuck on *loading* icon, it doesn't do the same behavior as it should (which is after ENTER a new frame on the screen show up with a list of products).

    I think it have to do with the way of sending the .submit() maybe it needs some kind of value?

    Look here:

    https://imgur.com/a/h6oiquJ

    Saturday, July 21, 2018 5:16 PM
  • Ajax sites do not use "submit" to submit a form.   THe use remote communications schemes to navigate.  Most ajax sites and most modern web sites do no allow "screen scraping"  They are designed to prevent the type of automation you are attempting. 

    If you inspect the JavaScript from the page you will see how the page is designed and can see how the page is evented.


    \_(ツ)_/


    • Edited by jrv Saturday, July 21, 2018 9:48 PM
    Saturday, July 21, 2018 9:47 PM
  • Ajax sites do not use "submit" to submit a form.   THe use remote communications schemes to navigate.  Most ajax sites and most modern web sites do no allow "screen scraping"  They are designed to prevent the type of automation you are attempting. 

    If you inspect the JavaScript from the page you will see how the page is designed and can see how the page is evented.


    \_(ツ)_/


    For the last 5 hours I'm sitting and trying to figure it out.

    I got the JS file from the website and deduct the stuff that is not related to what I'm looking for.

    Here is what I ended up with:

    https://codeshare.io/2BDVjp

    There is few things that got my attention but I tried everything I could think of and non worked:

    onSubmit: this.handleSearchSubmit

    return d("form", { onSubmit: u, className: l()("products__search", h, { "products__search--loading": i }) }, void 0, o.a.createElement(s.g, c({}, _, { size: "lg", tabIndex: "0", value: t, maxLength: "100", style: v, autoComplete: "off", onChange: p, placeholder: "Search", className: "products__search__input" }))

            E = M("h4", { className: "products__heading products__heading--md" },
                void 0, "Select the product you want to search"),
            O = function(e) {
                function t(e) {
                    r(this, t);
                    var n = i(this, (t.__proto__ || Object.getPrototypeOf(t)).call(this, e));
                    return n.scrollElementId = "Page__master-id",
                        n.state = { searchTerm: "", loading: !1, lockedProduct: !1, selectedProduct: !1, displayMode: n.getDefaultDisplayMode() },
                        n.handleScroll = n.handleScroll.bind(n), n.clearSearchTerm = n.clearSearchTerm.bind(n),
                        n.handleSearchChange = n.handleSearchChange.bind(n), n.handleSearchSubmit = n.handleSearchSubmit.bind(n), n
                }


    I know it's a lot to ask but if you have some time to take a look at it (https://codeshare.io/2BDVjp) and tell me what I need to do I will appreciate it, also would totally understand if it's too much to ask and you don't have the time.

    Thanks!



    • Edited by Day4Night Sunday, July 22, 2018 5:41 AM
    Sunday, July 22, 2018 5:40 AM