(Python Selenium) I want to check the settings of the download destination of WebDriver

Check the settings for downloading the WebDriver

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.

Recommended Posts

(Python Selenium) I want to check the settings of the download destination of WebDriver
I want to know the features of Python and pip
I want to output the beginning of the next month with Python
I want to check the position of my face with OpenCV!
I want to batch convert the result of "string" .split () in Python
I want to explain the abstract class (ABCmeta) of Python in detail.
I made a program to check the size of a file in Python
I want to customize the appearance of zabbix
Python: I want to measure the processing time of a function neatly
I want to display the progress in Python!
I want to use Python in the environment of pyenv + pipenv on Windows 10
I tried to automate the 100 yen deposit of Rakuten horse racing (python / selenium)
I want to crop the image along the contour instead of the rectangle [python OpenCV]
Easy way to check the source of Python modules
I want to grep the execution result of strace
I want to inherit to the back with python dataclass
I want to fully understand the basics of Bokeh
I want to write in Python! (3) Utilize the mock
I want to use the R dataset in python
I want to increase the security of ssh connections
I tried to summarize the string operations of Python
I want to get custom data attributes of html as elements using Python Selenium
I tried to automate the article update of Livedoor blog with Python and selenium.
I want to specify another version of Python with pyvenv
maya Python I want to fix the baked animation again.
I want to start a lot of processes from python
I want to use only the normalization process of SudachiPy
I want to get the operation information of yahoo route
I made a function to check the model of DCGAN
I want to automatically attend online classes with Python + Selenium!
[Python] I want to use the -h option with argparse
[Python] I tried to visualize the follow relationship of Twitter
I want to judge the authenticity of the elements of numpy array
Debug by attaching to the Python process of the SSH destination
Keras I want to get the output of any layer !!
I want to know the legend of the IT technology world
I want to change the symbolic link destination of / lib64 from / usr / lib64 to / my-lib64 on CentOS
[Python] I want to make a 3D scatter plot of the epicenter with Cartopy + Matplotlib!
I want to debug with Python
I want to get the name of the function / method being executed
I want to manually assign the training parameters of the [Pytorch] model
How to determine the existence of a selenium element in Python
I want to know the weather with LINE bot feat.Heroku + Python
How to check the memory size of a variable in Python
[Introduction to Python] I compared the naming conventions of C # and Python.
I want to run the Python GUI when starting Raspberry Pi
I wrote the code to write the code of Brainf * ck in python
How to check the memory size of a dictionary in Python
LINEbot development, I want to check the operation in the local environment
I want to use both key and value of Python iterator
I used the worldcup command to check the outcome of the World Cup.
I want to know the population of each country in the world.
I tried to improve the efficiency of daily work with Python
I want to extract an arbitrary URL from the character string of the html source with python
I want to clear up the question of the "__init__" method and the "self" argument of a Python class.
I want to pin Spyder to the taskbar
I want to output to the console coolly
Check the behavior of destructor in Python
How to check the version of Django
I want to handle the rhyme part1
Check the existence of the file with python