diff --git a/examples/raw_performance_logs.py b/examples/raw_performance_logs.py new file mode 100644 index 00000000000..7ee984c5b41 --- /dev/null +++ b/examples/raw_performance_logs.py @@ -0,0 +1,7 @@ +from rich.pretty import pprint +from seleniumbase import SB + +with SB(log_cdp=True) as sb: + sb.open("seleniumbase.io/demo_page") + sb.sleep(1) + pprint(sb.driver.get_log("performance")) diff --git a/examples/test_highlight_elements.py b/examples/test_highlight_elements.py new file mode 100644 index 00000000000..f28eac1d8df --- /dev/null +++ b/examples/test_highlight_elements.py @@ -0,0 +1,11 @@ +from seleniumbase import BaseCase +BaseCase.main(__name__, __file__) + + +class HighlightTest(BaseCase): + def test_highlight_inputs(self): + self.open("https://seleniumbase.io/demo_page") + if self.headed: + self.highlight_elements("input", loops=2) # Default: 4 + else: + self.highlight_elements("input", loops=1, limit=3) diff --git a/help_docs/method_summary.md b/help_docs/method_summary.md index 967f4c5de94..2b746b4a84b 100644 --- a/help_docs/method_summary.md +++ b/help_docs/method_summary.md @@ -386,6 +386,8 @@ self.highlight_if_visible(selector, by="css selector", loops=4, scroll=True) self.highlight(selector, by="css selector", loops=4, scroll=True, timeout=None) +self.highlight_elements(selector, by="css selector", loops=4, scroll=True, limit=0) + self.press_up_arrow(selector="html", times=1, by="css selector") self.press_down_arrow(selector="html", times=1, by="css selector") diff --git a/mkdocs_build/requirements.txt b/mkdocs_build/requirements.txt index 54f3d2053c2..6e3fe0f4227 100644 --- a/mkdocs_build/requirements.txt +++ b/mkdocs_build/requirements.txt @@ -20,7 +20,7 @@ lxml==5.2.1 pyquery==2.0.0 readtime==3.0.0 mkdocs==1.6.0 -mkdocs-material==9.5.20 +mkdocs-material==9.5.21 mkdocs-exclude-search==0.6.6 mkdocs-simple-hooks==0.1.5 mkdocs-material-extensions==1.3.1 diff --git a/seleniumbase/__version__.py b/seleniumbase/__version__.py index c3add5ab03d..8d93f2cb5e8 100755 --- a/seleniumbase/__version__.py +++ b/seleniumbase/__version__.py @@ -1,2 +1,2 @@ # seleniumbase package -__version__ = "4.26.2" +__version__ = "4.26.3" diff --git a/seleniumbase/fixtures/base_case.py b/seleniumbase/fixtures/base_case.py index 0a23225eb1e..1851ad9d43b 100644 --- a/seleniumbase/fixtures/base_case.py +++ b/seleniumbase/fixtures/base_case.py @@ -60,6 +60,7 @@ def test_anything(self): from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.remote.remote_connection import LOGGER +from selenium.webdriver.remote.webelement import WebElement from seleniumbase import config as sb_config from seleniumbase.__version__ import __version__ from seleniumbase.common import decorators @@ -5645,6 +5646,40 @@ def highlight_if_visible( if self.is_element_visible(selector, by=by): self.__highlight(selector, by=by, loops=loops, scroll=scroll) + def __highlight_element(self, element, loops=None, scroll=True): + self.__check_scope() + if not loops: + loops = settings.HIGHLIGHTS + if scroll and self.browser != "safari": + try: + self.__slow_scroll_to_element(element) + except Exception: + pass + if self.highlights: + loops = self.highlights + if self.browser == "ie": + loops = 1 # Override previous setting because IE is slow + loops = int(loops) + if self.headless or self.headless2 or self.xvfb: + # Headless modes have less need for highlighting elements. + # However, highlight() may be used as a sleep alternative. + loops = int(math.ceil(loops * 0.5)) + o_bs = "" # original_box_shadow + try: + style = element.get_attribute("style") + except Exception: + self.wait_for_ready_state_complete() + time.sleep(0.12) + style = element.get_attribute("style") + if style: + if "box-shadow: " in style: + box_start = style.find("box-shadow: ") + box_end = style.find(";", box_start) + 1 + original_box_shadow = style[box_start:box_end] + o_bs = original_box_shadow + self.__highlight_element_with_js(element, loops, o_bs) + time.sleep(0.065) + def __highlight( self, selector, by="css selector", loops=None, scroll=True ): @@ -5733,13 +5768,16 @@ def highlight( ): """This method uses fancy JavaScript to highlight an element. @Params - selector - the selector of the element to find + selector - the selector of the element to find (Accepts WebElement) by - the type of selector to search by (Default: CSS) loops - # of times to repeat the highlight animation (Default: 4. Each loop lasts for about 0.2s) scroll - the option to scroll to the element first (Default: True) timeout - the time to wait for the element to appear """ self.__check_scope() + if isinstance(selector, WebElement): + self.__highlight_element(selector, loops=loops, scroll=scroll) + return if not timeout: timeout = settings.SMALL_TIMEOUT self.wait_for_element_visible(selector, by=by, timeout=timeout) @@ -5751,6 +5789,31 @@ def highlight( action = ["hi_li", selector, origin, time_stamp] self.__extra_actions.append(action) + def highlight_elements( + self, + selector, + by="css selector", + loops=None, + scroll=True, + limit=0, + ): + if not limit: + limit = 0 # 0 means no limit + limit = int(limit) + count = 0 + elements = self.find_elements(selector, by=by) + for element in elements: + try: + if element.is_displayed(): + self.__highlight_element( + element, loops=loops, scroll=scroll + ) + count += 1 + except Exception: + pass + if limit > 0 and count >= limit: + break + def press_up_arrow(self, selector="html", times=1, by="css selector"): """Simulates pressing the UP Arrow on the keyboard. By default, "html" will be used as the CSS Selector target.