简体   繁体   中英

Where does the \n come from?

I'm trying to test a string. I get the innerHTML, yet it has extra u'\\n and \\n'

AssertionError: u'\n<p><strong>Codul de Utilizator/Parola introduse nu sunt corecte!</strong></p>\n' != '<p><strong>Codul de Utilizator/Parola introduse nu sunt corecte!</strong></p>'

HTML from site

<div id="errorDiv1" class="error" style="display: block;">
   <p><strong>Codul de Utilizator/Codul introduse nu sunt corecte!</strong></p>
</div>

Code

        error = self.driver.find_element_by_id("errorDiv1").get_attribute('innerHTML')
        expected_error = '<p><strong>Codul de Utilizator/Parola introduse nu sunt corecte!</strong></p>'
        self.assertEqual(error, expected_error)

What is happening here? Where they come from?

\\n is the new line character.

It's present since there's a new line character between line 1 and line 2 of your HTML code.

u'' defines a Unicode String in python Unicode Strings .

'\\n' is a escape sequence and stands for Linefeed . Linefeed means advancing the printing area by one line.

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