title: Using Xpath to change innerHTML in Selenium; Python creates multiple escapes that lead to SyntaxError: Invalid or unexpected token
body: <p>The script is as follows:</p>
  
  <p><code>script = "document.evaluate(\"(.//*[@aria-label='Message Body'])[2]\", document).iterateNext().innerHTML = '&lt;b&gt;Test&lt;/b&gt;&lt;br/&gt;&lt;i&gt;html&lt;/i&gt;'"</code></p>
  
  <p>As you can see, I need to escape at least one of quotes, or apostrophes.</p>
  
  <p>Other variant may be:</p>
  
  <p><code>script = 'document.evaluate("(.//*[@aria-label=\'Message Body\'])[2]", document).iterateNext().innerHTML = "&lt;b&gt;Test&lt;/b&gt;&lt;br/&gt;&lt;i&gt;html&lt;/i&gt;"'</code></p>
  
  <p>When used with <code>driver.execute_script(script)</code>, the text first gets its <code>\</code> escaped once, and following its execution inside Selenium code, it is getting escaped another time, leading to <code>\\\'</code> passed to the Java Script engine, which results in a <code>SyntaxError: Invalid or unexpected token</code> error.</p>
  
  <p>I tried with <code>r'test\''</code> but that ends up having much more escape characters.</p>
  
  <p>Is there a way to pass that script correctly to the driver?</p>