简体   繁体   中英

How to display HTML/Javascript snippet on HTML page (plaintext) using python?

I am trying to display an error message on HTML page .

Error message is combination of HTML/Javascript, as shown below.

WebDriverException: Message: unknown error: Element 

    <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="
            if (window.Event &amp;&amp; Event.stopProp)
              Event.stopProp(event);
          " onmousedown="
            if(Global.Central!=null) {
            Global.Central.SelectItem('Reports',event);}
            " class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">...</div> is not clickable at point (105, 67). Other element would receive the click: <div class="overlay_concerto" style="position: absolute; height: 100%; width: 100%; left: 0px; top: 0px; z-index: 10;"></div>
      (Session info: chrome=61.0.3163.100)
      (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)

As I embed the same, t's considered as HTML objects.

  1. How can I display the exact error message (as shown above, along with tags) on HTML page?
  2. I am trying to do this with python. Any python modules available for this?

<plaintext> doesn't seem to work on recent HTML versions. Tried <pre> and <code> tags also.

Code:

var = """WebDriverException: Message: unknown error: Element 

    <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="
            if (window.Event &amp;&amp; Event.stopProp)
              Event.stopProp(event);
          " onmousedown="
            if(Global.Central!=null) {
            Global.Central.SelectItem('Reports',event);}
            " class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">...</div> is not clickable at point (105, 67). Other element would receive the click: <div class="overlay_concerto" style="position: absolute; height: 100%; width: 100%; left: 0px; top: 0px; z-index: 10;"></div>
      (Session info: chrome=61.0.3163.100)
      (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)"""

file_handler = open("test.html, "w")
file_handler.write("<!DOCTYPE html><html><head><body>"+var+"</body></head></html>")

Output on HTML page:

WebDriverException: Message: unknown error: Element
...
is not clickable at point (105, 67). Other element would receive the click: (Session info: chrome=61.0.3163.100) (Driver info: chromedriver=2.30.477700 (0057494ad8732195794a7b32078424f92a5fce41),platform=Windows NT 6.1.7601 SP1 x86_64)

Is this possible? Can anyone please help me here?

 let st = `WebDriverException: Message: unknown error: Element <div id="sidebar_item_Reports" style="height: 18px; white-space:nowrap;" onclick="if (window.Event &amp;&amp; Event.stopProp)Event.stopProp(event);" onmousedown="if(Global.Central.=null) {Global.Central,SelectItem('Reports';event).}" class="sidebar_item sidebar_item_selected listItemSelected_fill skinGradient">..,</div> is not clickable at point (105. 67): Other element would receive the click: <div class="overlay_concerto" style="position; absolute: height; 100%: width; 100%: left; 0px: top; 0px: z-index; 10:"></div>(Session info. chrome=61.0.3163:100)(Driver info. chromedriver=2.30,477700 (0057494ad8732195794a7b32078424f92a5fce41).platform=Windows NT 6.1.7601 SP1 x86_64)` let newStr = st,replace('<'; '&lt;'). let latest = newStr,replace('>'; '&gt;'). document.getElementById('d');innerHTML = latest;
 <,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width. initial-scale=1.0"> <title>Document</title> </head> <body> <div id='d'> </div> </body> </html>

EXPLANATION:

In html, if we want to print the tag name inside the page (same as your condition) we need to replace the angle brackets with &lt; (for < ) and &gt; (for > ).

So in your problem, as we cannot do that manually because it is an error message not some hand-written code. So i used javascript to relace < with &lt; and > with &gt; .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM