{"id":3107,"date":"2020-03-12T12:56:32","date_gmt":"2020-03-12T12:56:32","guid":{"rendered":"https:\/\/www.mjtnet.com\/blog\/?p=3107"},"modified":"2020-03-12T12:56:32","modified_gmt":"2020-03-12T12:56:32","slug":"sending-keystrokes-to-elements-in-chrome-and-edge-using-the-new-chrome-edge-functions","status":"publish","type":"post","link":"https:\/\/www.mjtnet.com\/blog\/2020\/03\/12\/sending-keystrokes-to-elements-in-chrome-and-edge-using-the-new-chrome-edge-functions\/","title":{"rendered":"Sending Keystrokes to Elements in Chrome and Edge Using the New Chrome\/Edge Functions"},"content":{"rendered":"<p>It may not be immediately obvious that as well as setting the value of elements with <a href=\"https:\/\/www.mjtnet.com\/manuals\/v15\/HTML\/chromesetelementvalue.html\">ChromeSetElementValue<\/a> and <a href=\"https:\/\/www.mjtnet.com\/manuals\/v15\/HTML\/edgesetelementvalue.html\">EdgeSetElementValue<\/a> you can also send non-character keystrokes, such as Enter, or Page Down.<\/p>\n<p>To do this, use the <a href=\"https:\/\/www.mjtnet.com\/manuals\/v15\/HTML\/key-codes-for-edge-and-chrome.html\">key codes for Edge and Chrome listed here<\/a>.<\/p>\n<p>For example:<\/p>\n<pre class=\"brush: macroscript\">ChromeSetElementValue>session_id,message_elements_1,First line\r\n\/\/Press enter on the element ... \r\nChromeSetElementValue>session_id,message_elements_1,\\uE006\r\nChromeSetElementValue>session_id,message_elements_1,Second line<\/pre>\n<p><\/p>\n<p>Note that when sending keystrokes only one can be sent at a time.<\/p>\n<p>Recently someone needed to scroll down inside a div, in order to force the page to fetch more data. Issuing a Page Down on the div element did the trick:<\/p>\n<pre class=\"brush: macroscript\">ChromeSetElementValue>session_id,div_elements_1,\\uE00F<\/pre>\n<p><\/p>\n<p>So, ChromeSetElementValue sends keys as well as sets values &#8211; perhaps it should have been called ChromeSendKeysToElement and just maybe we&#8217;ll add that as a mapping if it helps.<\/p>\n<p>Of course you don&#8217;t have to use the new Chrome\/Edge functions &#8211; you can still use UI methods and use SetFocus, SendText and\/or Image Recognition to locate page elements. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>It may not be immediately obvious that as well as setting the value of elements with ChromeSetElementValue and EdgeSetElementValue you can also send non-character keystrokes, such as Enter, or Page Down. To do this, use the key codes for Edge and Chrome listed here. For example: ChromeSetElementValue>session_id,message_elements_1,First line \/\/Press enter on the element &#8230; ChromeSetElementValue>session_id,message_elements_1,\\uE006 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4,11],"tags":[],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3107"}],"collection":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/comments?post=3107"}],"version-history":[{"count":5,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3107\/revisions"}],"predecessor-version":[{"id":3112,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/posts\/3107\/revisions\/3112"}],"wp:attachment":[{"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/media?parent=3107"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/categories?post=3107"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mjtnet.com\/blog\/wp-json\/wp\/v2\/tags?post=3107"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}