\ n来自哪里?

时间:2018-03-13 15:29:27

标签: python html selenium

我正在尝试测试字符串。我得到了innerHTML,但它有额外的u'\n\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

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

代码

        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)

这里发生了什么?他们来自哪里?

2 个答案:

答案 0 :(得分:1)

\n是换行符。

它存在,因为HTML代码的第1行和第2行之间有一个新的行字符。

答案 1 :(得分:0)

u''在python Unicode Strings中定义了一个Unicode字符串。

'\n'是一个转义序列,代表Linefeed。换行意味着将打印区域推进一行。

相关问题