Reputation: 8362
I am trying to match a H1 tag on a page that has several h1 tags using partial text.
For this example the text is "Your booking was"
<header data-v-20d51c72="" data-v-3cdc5826="" class="default__title">
<h1 data-v-20d51c72="" data-v-3cdc5826="" class="default__title">Your booking was unsuccessful.</h1>
</header>
I can locate against the full text like this
page.querySelector('//h1[normalize-space()="Your booking was unsuccessful."]')
I can also get a list of all h1 tags and then check the innerHTML for all
[handle for handle in page.querySelectorAll('//h1') if handle.innerHTML().startswith('Your booking was')]
But this way, I can't wait for the handle to appear.
How can I write a selector so that I can match against a partial tag so that I can use page.WaitForSelector()
on it?
Upvotes: 1
Views: 6102
Reputation: 8362
Taking a hint from this SO question a working selector is
handle = page.querySelector('//h1[contains(., "Your booking was")]')
Where
print(handle.innerHTML())
prints 'Your booking was unsuccessful.'
Upvotes: 3