Exploring the WebExecute function, I would like to know how can I send key (or TypeElement) to the element in focus. Here is a toy code using Google.

WebExecute["OpenPage" -> "www.google.com"]
WebExecute["ClickElement" -> "XPath" -> "//input[@name = 'q']"];

Now that the text area is selected, I tried to implement this post Javascript solution (with no success) using:


Any clue on how to do this in Mathematica?

enter image description here

Note: I know that for this toy code I can type in the text area using:

WebExecute["TypeElement" -> {First@WebExecute["LocateElements" -> "XPath" -> "//input[@name = 'q']"], "Test"}]

But my real case is more complex than this, and type in the focus area should work.


1 Answer 1


After some web search, I found this solution using this interesting CSS Pseudo-class focus.

WebExecute["OpenPage" -> "www.google.com"]
input = First@WebExecute["LocateElements" -> "CSSSelector" -> "input:focus"]
WebExecute["TypeElement" -> {input,"Test"}];

Here is the reference post.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.