Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to extract multiline content from the <pre> tag in html using Selenium

Originally the element looks like this:

<pre>test_line1 test_line2 test_line3 test4</pre>

but when i double click it it looks like this:

<pre>test_line1
test_line2
test_line3
test4</pre>

linebreaks here are not recognized as \n or
what to do? i need to extract text and compare it with expected text
and expected text can be written only in single line

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

String elementText = element.getText();
Assert.assertTrue(elementText,"test_line1 test_line2 test_line3 test4");
 Assert.assertTrue(elementText,"test_line1\ntest_line2\ntest_line3\ntest4");

>Solution :

You can try with something like this:

actualText.replaceAll("(\r\n|\n)", "");

This will remove all potential new line symbols from the text.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading