\n来自哪里?

2024-10-03 02:43:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试一根绳子。我得到了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)

这里发生了什么?他们从哪里来?你知道吗


Tags: selfdividdeerrornustronginnerhtml
2条回答

\n是新行字符。你知道吗

它的出现是因为在HTML代码的第1行和第2行之间有一个新行字符。你知道吗

u''在pythonUnicode Strings中定义Unicode字符串。你知道吗

'\n'是一个转义序列,代表Linefeed。换行是指将打印区域前进一行。你知道吗

相关问题 更多 >