Очень просто querySelector подойдет
// first h1 in header
console.log(
document.querySelector("header > h1").textContent
)
// first h1 in document:
console.log(
document.querySelector("h1").textContent
)
header > h1 {
color: green
}
<header>
<h1>I want to select this</h1>
<div>
<h1>Welcome to the world!</h1>
<p>I don't like apples</p>
</div>
</header>