<commit_before># Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import time

from telemetry import page_interaction
from telemetry import util

class ClickElementInteraction(page_interaction.PageInteraction):
  def __init__(self, attributes=None):
    super(ClickElementInteraction, self).__init__(attributes)

  def PerformInteraction(self, page, tab):
    def DoClick():
      assert hasattr(self, 'selector') or hasattr(self, 'text')
      if hasattr(self, 'selector'):
        code = 'document.querySelector(\'' + self.selector + '\').click();'
        tab.runtime.Execute(code)
      else:
        click_element = """
            function clickElement(element, text) {
              if (element.innerHTML == text) {
                element.click();
                return true;
              }
              for (var i in element.childNodes) {
                if (clickElement(element.childNodes[i], text))
                  return true;
              }
              return false;
            }"""
        tab.runtime.Execute(click_element)
        code = 'clickElement(document, "' + self.text + '");'
        if not tab.runtime.Evaluate(code):
          raise page_interaction.PageInteractionFailed(
              'Cannot find element with text ' + self.text)

    if hasattr(self, 'wait_for_navigate'):
      tab.page.PerformActionAndWaitForNavigate(DoClick)<commit_msg>Telemetry: error messages & memory benchmark fix<commit_after># Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import time

from telemetry import inspector_runtime
from telemetry import page_interaction
from telemetry import util

class ClickElementInteraction(page_interaction.PageInteraction):
  def __init__(self, attributes=None):
    super(ClickElementInteraction, self).__init__(attributes)

  def PerformInteraction(self, page, tab):
    def DoClick():
      assert hasattr(self, 'selector') or hasattr(self, 'text')
      if hasattr(self, 'selector'):
        code = 'document.querySelector(\'' + self.selector + '\').click();'
        try:
          tab.runtime.Execute(code)
        except inspector_runtime.EvaluateException:
          raise page_interaction.PageInteractionFailed(
              'Cannot find element with selector ' + self.selector)
      else:
        click_element = """
            function clickElement(element, text) {
              if (element.innerHTML == text) {
                element.click();
                return true;
              }
              for (var i in element.childNodes) {
                if (clickElement(element.childNodes[i], text))
                  return true;
              }
              return false;
            }"""
        tab.runtime.Execute(click_element)
        code = 'clickElement(document, "' + self.text + '");'
        if not tab.runtime.Evaluate(code):
          raise page_interaction.PageInteractionFailed(
              'Cannot find element with text ' + self.text)

    if hasattr(self, 'wait_for_navigate'):
      tab.page.PerformActionAndWaitForNavigate(DoClick)
{'fraction_non_alphanumeric': 0.09821976672805402, 'fraction_numerical': 0.0024554941682013503, 'mean_word_length': 2.5080731969860066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3011264', 'n_tokens_mistral': 868, 'n_tokens_neox': 842, 'n_words': 238}