Best Python code snippet using SeleniumBase
test_shadow_dom.py
Source:test_shadow_dom.py
...4 This uses the "::shadow" selector for piercing shadow-root elements.5 Here's the URL that contains Shadow DOM: chrome://downloads/ """6from seleniumbase import BaseCase7class ShadowDomTests(BaseCase):8 def download_tar_file_from_pypi(self, package):9 self.open("https://pypi.org/project/%s/#files" % package)10 pkg_header = self.get_text("h1.package-header__name").strip()11 pkg_name = pkg_header.replace(" ", "-")12 tar_file = pkg_name + ".tar.gz"13 tar_selector = 'div#files a[href$="%s"]' % tar_file14 self.delete_downloaded_file_if_present(tar_file, browser=True)15 self.click(tar_selector)16 return tar_file17 def test_shadow_dom(self):18 if self.browser != "chrome":19 self.open("data:,")20 print("\n This test is for Google Chrome only!")21 self.skip("This test is for Google Chrome only!")22 if self.headless:23 self.open("data:,")24 print("\n This test doesn't run in headless mode!")25 self.skip("This test doesn't run in headless mode!")26 # Download Python package files from PyPI27 file_name_1 = self.download_tar_file_from_pypi("sbase")28 file_name_2 = self.download_tar_file_from_pypi("seleniumbase")29 self.assert_downloaded_file(file_name_1, browser=True)30 self.assert_downloaded_file(file_name_2, browser=True)31 # Navigate to the Chrome downloads page.32 self.open("chrome://downloads/")33 # Shadow DOM selectors34 search_icon = (35 "downloads-manager::shadow downloads-toolbar::shadow"36 " cr-toolbar::shadow cr-toolbar-search-field::shadow"37 " cr-icon-button"38 )39 search_input = (40 "downloads-manager::shadow downloads-toolbar::shadow"41 " cr-toolbar::shadow cr-toolbar-search-field::shadow"42 " #searchInput"...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!