The term Doujinshi is rather broad, encompassing any self-published work. Sometimes, although rarely, even big name authors have created some doujinshi.
Wikipedia has a pretty decent article which defines it as:
Dōjinshi (同人誌{どうじんし}), often transliterated as doujinshi) is the Japanese term for self-published works, usually magazines, manga or novels. Dōjinshi are often the work of amateurs, though some professional artists participate as a way to publish material outside the regular industry.
These self-published works are almost always inspired by work created by someone else, rather than being original works. Since the authors usually don't have original ideas to write about, instead they want to express their love for a series by writing stories that could have happened, which is why you're often seeing these sexual situations in doujinshi. Sex is popular, and it is generally abstained from in source material. Thus writing about it is a good way to make your doujinshi popular easily, since many people will have had similar thoughts while reading the source.
As far as if there are doujinshi that do not involve sexual situations, the answer is of course. Since we are talking about self-published works, there is really no limit to what kind of stories you could find, just like in any fan fiction.
Finally, your question about finding out what is in them ahead of time, has already been asked here: How do I figure out the contents of doujinshi? While there isn't an answer to that question posted, it seems the consensus from the comments is that outside of learning about the contents from a doujin circle, it is rather hard to know what to expect.