How to work with shadow root with selenium in Python?

I would like to upload file at quick-actions.express.adobe.com, so I do the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>driver.get("https://quick-actions.express.adobe.com/remove-background")
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app")
shadow_root = shadow_host.shadow_root
file_input = shadow_root.find_element(By.TAG_NAME, "input")
</code>
<code>driver.get("https://quick-actions.express.adobe.com/remove-background") WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body"))) shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app") shadow_root = shadow_host.shadow_root file_input = shadow_root.find_element(By.TAG_NAME, "input") </code>
driver.get("https://quick-actions.express.adobe.com/remove-background")
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app")
shadow_root = shadow_host.shadow_root
file_input = shadow_root.find_element(By.TAG_NAME, "input")

But it says selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator.

I tried to access the element directly, but it doesn’t work:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>file_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//input[@type="file"]'))
)
file_input.send_keys(file_path)
</code>
<code>file_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, '//input[@type="file"]')) ) file_input.send_keys(file_path) </code>
file_input = WebDriverWait(driver, 10).until(
     EC.presence_of_element_located((By.XPATH, '//input[@type="file"]'))
)
file_input.send_keys(file_path)

Is there any other way to upload the file there?

Upd.

It fails when multiple roots are used:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root
shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here
shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root
shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root
shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root
</code>
<code>shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root </code>
shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root
shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here
shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root
shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root
shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root

The problem is that there are multiple levels of nested shadow-doms on the page that contain your desired INPUT.

Here’s a couple levels of the pattern that you can follow,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://quick-actions.express.adobe.com/remove-background")
shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
</code>
<code>from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://quick-actions.express.adobe.com/remove-background") shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root </code>
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://quick-actions.express.adobe.com/remove-background")

shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root

Just keep adding levels of shadow-root until you get to the level that has the desired INPUT and go from there…

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

How to work with shadow root with selenium in Python?

I would like to upload file at quick-actions.express.adobe.com, so I do the following:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>driver.get("https://quick-actions.express.adobe.com/remove-background")
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app")
shadow_root = shadow_host.shadow_root
file_input = shadow_root.find_element(By.TAG_NAME, "input")
</code>
<code>driver.get("https://quick-actions.express.adobe.com/remove-background") WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body"))) shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app") shadow_root = shadow_host.shadow_root file_input = shadow_root.find_element(By.TAG_NAME, "input") </code>
driver.get("https://quick-actions.express.adobe.com/remove-background")
WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.TAG_NAME, "body")))
shadow_host = driver.find_element(By.TAG_NAME, "qa-standalone-app")
shadow_root = shadow_host.shadow_root
file_input = shadow_root.find_element(By.TAG_NAME, "input")

But it says selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: invalid locator.

I tried to access the element directly, but it doesn’t work:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>file_input = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//input[@type="file"]'))
)
file_input.send_keys(file_path)
</code>
<code>file_input = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, '//input[@type="file"]')) ) file_input.send_keys(file_path) </code>
file_input = WebDriverWait(driver, 10).until(
     EC.presence_of_element_located((By.XPATH, '//input[@type="file"]'))
)
file_input.send_keys(file_path)

Is there any other way to upload the file there?

Upd.

It fails when multiple roots are used:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root
shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here
shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root
shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root
shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root
</code>
<code>shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root </code>
shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
shadow_root3 = shadow_root2.find_element(By.CSS_SELECTOR, "qa-app-root").shadow_root
shadow_root4 = shadow_root3.find_element(By.TAG_NAME, "qa-app").shadow_root # fails here
shadow_root5 = shadow_root4.find_element(By.CSS_SELECTOR, "qa-remove-background-editor").shadow_root
shadow_root6 = shadow_root5.find_element(By.CSS_SELECTOR, "qa-workspace").shadow_root
shadow_root7 = shadow_root6.find_element(By.CSS_SELECTOR, "qa-file-upload").shadow_root

The problem is that there are multiple levels of nested shadow-doms on the page that contain your desired INPUT.

Here’s a couple levels of the pattern that you can follow,

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("https://quick-actions.express.adobe.com/remove-background")
shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root
</code>
<code>from selenium import webdriver from selenium.webdriver.common.by import By driver = webdriver.Chrome() driver.get("https://quick-actions.express.adobe.com/remove-background") shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root </code>
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://quick-actions.express.adobe.com/remove-background")

shadow_root1 = driver.find_element(By.CSS_SELECTOR, "qa-standalone-app").shadow_root
shadow_root2 = shadow_root1.find_element(By.CSS_SELECTOR, "standalone-quick-action").shadow_root

Just keep adding levels of shadow-root until you get to the level that has the desired INPUT and go from there…

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật