0

I am looking to retrieve a focused element's HTML. Looking at the webdriver.io documentation, the method .getActiveElement() is supposed to do the trick. However, my IDE (WebStorm) shows an error stating that it is an "unresolved function or method" (the method isn't recognized). I've also seen someone mention the method .elementActive(), however this method shows up unrecognized as well.

Help! How can I retrieve the HTML of the current focused element?

Brian
  • 135
  • 4
  • 16
  • In javascript this seems to be an already existing answer: https://stackoverflow.com/a/497108/7919626 – Word Rearranger Feb 11 '19 at 21:31
  • Thanks for the very quick response NTR! I have tried this as well (document.activeElement), however I get the referenceError "document is not defined". – Brian Feb 11 '19 at 22:00
  • Are you writing your javascript inside a – Word Rearranger Feb 11 '19 at 22:08
  • All javascript is being written in .js files. The purpose of this project is to automate testing of a webpage. I do not have the source code of the webpage. – Brian Feb 11 '19 at 22:13
  • 1
    Hi .. are you in v5 or v4 version of wdio? Because getActiveElement is of V5 and elementActive is of V4 – Naveen Thiyagarajan Feb 12 '19 at 04:01

1 Answers1

2

If you're using WebdriverIO v5, you should be able to run the following:

const activeElement = $(function () { return document.activeElement });
const html = activeElement.getHTML();
console.log(html);

https://webdriver.io/docs/selectors.html#js-function

Kevin Lamping
  • 2,292
  • 16
  • 20