Home > Back-end >  How to extract multiline content from the <pre> tag in html using Selenium
How to extract multiline content from the <pre> tag in html using Selenium

Time:12-01

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

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

CodePudding user response:

You can try with something like this:

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

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

  • Related