Concatenating elements into body tag

Hi - Is it possible to combine multiple parts of a page into the body tag?

For example let’s say there is an image with a caption and it has

and this is outside the main body, which is in

I want to extract both the caption and the body and join them together.

I can do this:
body: //div[@class=‘caption’] | //div[@id=‘body’]

But that operates as an OR and will return the first and if not the second. How can I join them so I get both?


Hi there, your example is in fact the correct way to do it. You should get both elements returned. See for example: (click ‘Test’ to apply the XPath)

If you’re not getting both elements, you might want to look to see if the class attribute has more values than just “caption”. If it does, you’ll need to use something like: //div[contains(@class, 'caption')]

The downside to this approach is that if <div id="body"> stops appearing in the HTML you’re targetting some time in the future, but <div class="caption"> remains, you’ll get only the caption and not the body.

Thanks! I’ll do some testing.

1 Like