| 698 | self.click(selector, by=by, timeout=timeout, delay=0.25) |
| 699 | |
| 700 | def double_click(self, selector, by="css selector", timeout=None): |
| 701 | self.__check_scope() |
| 702 | if not timeout: |
| 703 | timeout = settings.SMALL_TIMEOUT |
| 704 | if self.timeout_multiplier and timeout == settings.SMALL_TIMEOUT: |
| 705 | timeout = self.__get_new_timeout(timeout) |
| 706 | original_selector = selector |
| 707 | original_by = by |
| 708 | selector, by = self.__recalculate_selector(selector, by) |
| 709 | element = page_actions.wait_for_element_visible( |
| 710 | self.driver, |
| 711 | selector, |
| 712 | by, |
| 713 | timeout=timeout, |
| 714 | original_selector=original_selector, |
| 715 | ) |
| 716 | self.__demo_mode_highlight_if_active(original_selector, original_by) |
| 717 | if not self.demo_mode and not self.slow_mode: |
| 718 | self.__scroll_to_element(element, selector, by) |
| 719 | self.wait_for_ready_state_complete() |
| 720 | if self.__needs_minimum_wait(): |
| 721 | time.sleep(0.02) |
| 722 | # Find the element one more time in case scrolling hid it |
| 723 | element = page_actions.wait_for_element_visible( |
| 724 | self.driver, |
| 725 | selector, |
| 726 | by, |
| 727 | timeout=timeout, |
| 728 | original_selector=original_selector, |
| 729 | ) |
| 730 | pre_action_url = None |
| 731 | with suppress(Exception): |
| 732 | pre_action_url = self.driver.current_url |
| 733 | try: |
| 734 | if self.browser == "safari": |
| 735 | # Jump to the "except" block where the other script should work |
| 736 | raise Exception("This Exception will be caught.") |
| 737 | actions = ActionChains(self.driver) |
| 738 | actions.double_click(element).perform() |
| 739 | except Exception: |
| 740 | css_selector = self.convert_to_css_selector(selector, by=by) |
| 741 | css_selector = re.escape(css_selector) # Add "\\" to special chars |
| 742 | css_selector = self.__escape_quotes_if_needed(css_selector) |
| 743 | double_click_script = ( |
| 744 | """var targetElement1 = document.querySelector('%s'); |
| 745 | var clickEvent1 = document.createEvent('MouseEvents'); |
| 746 | clickEvent1.initEvent('dblclick', true, true); |
| 747 | targetElement1.dispatchEvent(clickEvent1);""" |
| 748 | % css_selector |
| 749 | ) |
| 750 | if ":contains\\(" not in css_selector: |
| 751 | self.execute_script(double_click_script) |
| 752 | else: |
| 753 | double_click_script = ( |
| 754 | """var targetElement1 = arguments[0]; |
| 755 | var clickEvent1 = document.createEvent('MouseEvents'); |
| 756 | clickEvent1.initEvent('dblclick', true, true); |
| 757 | targetElement1.dispatchEvent(clickEvent1);""" |