Skip to content
Advertisement

selenium , how to print elements of this html in order as they are?

if this is the html of a whatsapp message (β€œπŸ˜… how πŸ‘Ή are you πŸŽ‚β€) then how to iterate through elements of this message and get them (print them) in order as they are by selenium?

JavaScript

output this should be

JavaScript

or output can also be like this

JavaScript

i tried this

JavaScript

this is giving output as

JavaScript

so how to get elements of this in order as they are ?

Advertisement

Answer

You can iterate over the child of span element and print the text in case of string and alt text in case of img tag

JavaScript

here is code sample for your use case It’s output is for this message is

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement