0

I am facing a problem, can anyone help me to sort this out:

Background: I have to create a backup of the code exist in the editor(Code mirror), so the use case is I have to copy the code from the editor and save it as .html file.

While using the element.getText() and writing to a file works fine but the issue is the getText()only get the code visible on the screen. Since the code lines vary so if I use javascript scrolls then it didn't work as some page on the editor (code mirror) would have 100 lines of code or some may have 2000.

Another solution I tried is to use Action class i.e mouse actions means Select all and copy i.e Keys.COMMAND, "c")).perform(); The Problem is here how can I copy the selected text to the clipboard or save the copied text to the string so that I can execute BufferedWriter class.

Would appreciate if anyone can help.

Tarun Sahu
  • 1
  • 1
  • 1
  • Possible duplicate of [Get HTML Source of WebElement in Selenium WebDriver using Python](http://stackoverflow.com/questions/7263824/get-html-source-of-webelement-in-selenium-webdriver-using-python) – Linh Nguyen Jan 12 '17 at 09:24
  • @LinhNguyen: Thanks for your reply. But going with that link couldn't solve my problem When you put some code here (https://codemirror.net/demo/theme.html) and try to extract the code, the code only is extracted that is in the view. However, when you scroll up you would see some div has been further added . Could you please help providing the solution for this? – Tarun Sahu Jan 12 '17 at 09:56

1 Answers1

0

Sorry I misunderstood your question.

For the link https://codemirror.net/demo/theme.html, to get the code, I think you should first scroll to the bottom of the editor using executeScript(Scroll to bottom of div?). After that, element.getText() should give you full code.

Update: You can also select the text by clicking on the editor and then pressing Ctrl + A, after that get selected text by executing javascript on the browser (Get the Highlighted/Selected text). You can then handle the text within your test script.

Community
  • 1
  • 1
Linh Nguyen
  • 1,120
  • 7
  • 13
  • Thanks. Yup, that's the one-time solution, I have 20 templates that have a code of different length means some page has 100 lines and some have 2000. Seven if I use a scroll I cannot be able to justify this for all the cases. – Tarun Sahu Jan 12 '17 at 10:34
  • You can always check if `class="CodeMirror-vscrollbar"` exists or not, and therefore decide to scroll or no – Linh Nguyen Jan 12 '17 at 10:41