Page.search_for() behaving inconsistently

After running get_textbox on a Rect to identify a text_string, subsequently attempting to call Page.search_for({text_string} will sometimes return nothing, even if we got our original Rect from Page.search_for()

Scenario:

First I have some text I am searching for (e.g. “Bullet Point text”) and then combining the results into one rect with my custom function ._combine_rects

rects_containing_bullet = self.unified_template_page.search_for(bullet)
redacted_rect = self._combine_rects(rects_containing_bullet)

This successfully returns the correct rects everytime and consistently works.

Next however, because the bullet point has a bullet point symbol somewhere off the to the left, I am expanding the width of the rect to the borders of the template page so we can capture it on a subsequent .search_for()

redacted_rect.x0 = 0
redacted_rect.x1 = page_width

Now, because the Rect width is wide enough that we should capture the bullet point if we run .get_textbox()

text_including_bullet = self.unified_template_page.get_textbox(redacted_rect)

This also consistently works and returns the correct text string (e.g. “● Bullet Point text”)

But when I try and capture the Rect for this text string including the bullet point, .search_for will occasionally be empty

text_including_bullet_rects = self.unified_template_page.search_for(text_including_bullet)

This is causing a flaky test because sometimes it will succeed in finding the rects and sometimes it will fail, even though it always succeeds at finding the text with .get_textbox() and our Rect is always populated

Any idea what’s happening here?

Welcome @youwonthavemy !

Please provide us with a minimal code snippet, but including the used font and potentially the PDF (if you didn’t create a new one).