PROBLEM TO BE SOLVED: To provide a thermosetting epoxy resin composition for encapsulating an optical semiconductor element excellent in handleability, transparency and crack resistance and the optical semiconductor element encapsulated by the same.SOLUTION: There is provided a thermosetting epoxy resin composition for encapsulating an optical semiconductor element containing (A) a prepolymer obtained by reacting (A-1) a triazine derivative epoxy resin, (A-2) at least one epoxy resin selected from a bisphenol A type epoxy resin, a bisphenol F type epoxy resin, a hydrogenated bisphenol A type epoxy resin and an alicyclic epoxy resin, (A-3) an acid anhydride curing agent which is a liquid at 50°C and (A-4) polycaprolactone polyol with a ratio of epoxy group equivalence/acid anhydride group equivalence of 0.6 to 2.0 and (B) a curing accelerator consisting of an onium salt represented by the formula (1). (1), where Xis a cation such as phosphonium ion and onium ion and Yis an anion such as organic borate ion and