55import subprocess
66from time import sleep
77
8+ from selenium .common import NoSuchElementException
89from selenium .webdriver .common .by import By
910from selenium .webdriver .common .keys import Keys
1011from selenium .webdriver .support import expected_conditions as EC
@@ -17,7 +18,7 @@ def parse_args():
1718 parser .add_argument ("--headless" , action = "store_true" )
1819 parser .add_argument ("--outfile" , "-o" , required = True )
1920 parser .add_argument ("--width" , type = int , default = 900 )
20- parser .add_argument ("--height" , type = int , default = 700 )
21+ parser .add_argument ("--height" , type = int , default = 1200 )
2122 return parser .parse_args ()
2223
2324
@@ -61,6 +62,21 @@ def submit_form(selenium, data):
6162 WebDriverWait (selenium , timeout = 5 ).until (EC .url_changes (url ))
6263
6364
65+ def find_including_toolbar (selenium , by , value ):
66+ """Find the toolbar elements within the shadow root DOM"""
67+ selectors = {
68+ By .ID : "#{}" ,
69+ By .CLASS_NAME : ".{}" ,
70+ By .TAG_NAME : "{}" ,
71+ By .CSS_SELECTOR : "{}" ,
72+ }
73+ try :
74+ return selenium .find_element (by , value )
75+ except NoSuchElementException :
76+ shadow_root = selenium .find_element (By .ID , "djDebugRoot" ).shadow_root
77+ return shadow_root .find_element (By .CSS_SELECTOR , selectors [by ].format (value ))
78+
79+
6480def main ():
6581 args = parse_args ()
6682 with example_server () as p :
@@ -73,12 +89,12 @@ def main():
7389
7490 selenium .get ("http://localhost:8000/admin/auth/user/" )
7591 # Check if SQL Panel is already visible:
76- sql_panel = selenium . find_element ( By .ID , "djdt-SQLPanel" )
92+ sql_panel = find_including_toolbar ( selenium , By .ID , "djdt-SQLPanel" )
7793 if not sql_panel :
7894 # Open the admin sidebar.
79- el = selenium . find_element ( By .ID , "djDebugToolbarHandle" )
95+ el = find_including_toolbar ( selenium , By .ID , "djDebugToolbarHandle" )
8096 el .click ()
81- sql_panel = selenium . find_element ( By .ID , "djdt-SQLPanel" )
97+ sql_panel = find_including_toolbar ( selenium , By .ID , "djdt-SQLPanel" )
8298 # Open the SQL panel.
8399 sql_panel .click ()
84100
0 commit comments