To check the download destination folder of the launched WebDriver, access chrome: // settings and check the download destination description. (** Since it was necessary to search the contents of ShadowDOM, the search with normal Javascript did not work. ** Therefore, it is necessary to describe the operation to open everything up to the DOM where the download destination is described. did.)
WebDriverModule.py
defaultDownloadPathElementName = "defaultDownloadPath"
class WebDriverModule(object):
def getChromeDefaultDownloadPath(self, driver:WebDriver)->str:
driver.get('chrome://settings')
WebDriverWait(driver,15).until(EC.presence_of_all_elements_located)
shadow_root1_1 = self.expandShadowElement(driver, driver.find_element_by_tag_name('settings-ui'))
shadow_root1_2 = self.expandShadowElement(driver, shadow_root1_1.find_element_by_tag_name('settings-main'))
shadow_root1_3 = self.expandShadowElement(driver, shadow_root1_2.find_element_by_tag_name('settings-basic-page'))
actionModule.clickElement(
driver,
shadow_root1_3.find_element_by_tag_name('paper-button')
)
shadow_root2_1 = self.expandShadowElement(driver, driver.find_element_by_tag_name('settings-ui'))
shadow_root2_2 = self.expandShadowElement(driver, shadow_root2_1.find_element_by_tag_name('settings-main'))
shadow_root2_3 = self.expandShadowElement(driver, shadow_root2_2.find_element_by_tag_name('settings-basic-page'))
shadow_root2_4 = self.expandShadowElement(driver, shadow_root2_3.find_element_by_tag_name('settings-downloads-page'))
return self.getTextFromElement(
shadow_root2_4.find_element_by_id(defaultDownloadPathElementName)
)
def expandShadowElement(self, driver:WebDriver, shadowElement:WebElement)->WebElement:
shadowRoot = driver.execute_script('return arguments[0].shadowRoot', shadowElement)
return shadowRoot
def getTextFromElement(element:WebElement)->str:
print(element.text)
return element.text
Now you can get the settings from the chrome settings screen where ShadowDOM is used.
that's all.