Skip to content

Commit

Permalink
browser_steps: add "click element containing text if exists" (#2629)
Browse files Browse the repository at this point in the history
  • Loading branch information
wrobelda authored and dgtlmoon committed Sep 17, 2024
1 parent 543cb20 commit a5ff1cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions changedetectionio/blueprint/browser_steps/browser_steps.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'Click element if exists': '1 0',
'Click element': '1 0',
'Click element containing text': '0 1',
'Click element containing text if exists': '0 1',
'Enter text in field': '1 1',
'Execute JS': '0 1',
# 'Extract text and use as filter': '1 0',
Expand Down Expand Up @@ -96,12 +97,24 @@ def action_goto_site(self, selector=None, value=None):
return self.action_goto_url(value=self.start_url)

def action_click_element_containing_text(self, selector=None, value=''):
logger.debug("Clicking element containing text")
if not len(value.strip()):
return
elem = self.page.get_by_text(value)
if elem.count():
elem.first.click(delay=randint(200, 500), timeout=3000)

def action_click_element_containing_text_if_exists(self, selector=None, value=''):
logger.debug("Clicking element containing text if exists")
if not len(value.strip()):
return
elem = self.page.get_by_text(value)
logger.debug(f"Clicking element containing text - {elem.count()} elements found")
if elem.count():
elem.first.click(delay=randint(200, 500), timeout=3000)
else:
return

def action_enter_text_in_field(self, selector, value):
if not len(selector.strip()):
return
Expand Down

0 comments on commit a5ff1cd

Please sign in to comment.