Improved waiting condition on opening toggle blocks

Now checks for the presence of "notion-unknown-block" blocks
This commit is contained in:
Leonardo Cavaletti 2020-05-24 17:15:35 +01:00
parent 7e5a11cb6a
commit 1bf31f2d32
2 changed files with 5 additions and 4 deletions

View File

@ -40,14 +40,15 @@ class toggle_block_has_opened(object):
toggle_content = self.toggle_block.find_element_by_css_selector("div:not([style]")
if toggle_content:
content_children = len(toggle_content.find_elements_by_tag_name("div"))
unknown_children = len(toggle_content.find_elements_by_class_name("notion-unknown-block"))
is_loading = len(
self.toggle_block.find_elements_by_class_name("loading-spinner")
)
log.debug(
f"Waiting for toggle block to load"
f" ({content_children} children so far and {is_loading} loaders)"
f" ({unknown_children} pending children blocks / {is_loading} loaders)"
)
if content_children > 3 and not is_loading:
if not unknown_children and not is_loading:
return True
else:
return False

View File

@ -287,9 +287,9 @@ class Parser:
"Timeout waiting for toggle block to open."
" Likely it's already open, but doesn't hurt to check."
)
except Exception as ex:
except Exception as exception:
log.error(
"Something went wrong while trying to open a toggle block"
f"Error trying to open a toggle block: {exception}"
)
opened_toggles.append(toggle_block)
# after all toggles have been opened, check the page again to see if