|
| 1 | +# Browsers |
| 2 | + |
| 3 | +Every supported browser has a default set of options and capabilities curated for you that are used by default. |
| 4 | + |
| 5 | +In case you need to customize the options or capabilities you can do so via the `default_options` and `default_capabilities` methods available within each browser module. |
| 6 | + |
| 7 | +Here is an example on how to do that: |
| 8 | + |
| 9 | +```python |
| 10 | +from botcity.web import WebBot, Browser |
| 11 | + |
| 12 | +# For Chrome |
| 13 | +from botcity.web.browsers.chrome import default_options, default_capabilities |
| 14 | +# For Firefox |
| 15 | +#from botcity.web.browsers.firefox import default_options, default_capabilities |
| 16 | +# For Edge |
| 17 | +#from botcity.web.browsers.edge import default_options, default_capabilities |
| 18 | + |
| 19 | + |
| 20 | +class Bot(WebBot): |
| 21 | + def action(self, execution=None): |
| 22 | + # Configure whether or not to run on headless mode |
| 23 | + self.headless = False |
| 24 | + |
| 25 | + # Fetch the default options for my preferred browser |
| 26 | + # Pass in the headless, download_folder_path and user_data_dir |
| 27 | + # to be used when building the default_options |
| 28 | + def_options = default_options( |
| 29 | + headless=self.headless, |
| 30 | + download_folder_path=self.download_folder_path, |
| 31 | + user_data_dir=None # Informing None here will generate a temporary directory |
| 32 | + ) |
| 33 | + |
| 34 | + # Add your customized argument |
| 35 | + def_options.add_argument("<My Special Argument>") |
| 36 | + |
| 37 | + # Update the options to use the customized Options. |
| 38 | + self.options = def_options |
| 39 | + |
| 40 | + # Fetch the default options for my preferred browser |
| 41 | + def_capabilities = default_capabilities() |
| 42 | + |
| 43 | + # Set of modify the key and value for my desired capability |
| 44 | + def_capabilities["<My Special Parameter>"] = "special value" |
| 45 | + |
| 46 | + # Update the capabilities to use the customized configurations. |
| 47 | + self.capabilities = def_capabilities |
| 48 | + |
| 49 | + ... |
| 50 | +``` |
| 51 | + |
| 52 | +## Specific Browser Modules |
| 53 | + |
| 54 | +Here are the documentation for the methods mentioned above for each of the supported browsers. |
| 55 | + |
| 56 | +### Chrome |
| 57 | +::: botcity.web.browsers.chrome.default_options |
| 58 | + rendering: |
| 59 | + heading_level: 4 |
| 60 | + |
| 61 | +::: botcity.web.browsers.chrome.default_capabilities |
| 62 | + rendering: |
| 63 | + heading_level: 4 |
| 64 | + |
| 65 | +### Firefox |
| 66 | +::: botcity.web.browsers.firefox.default_options |
| 67 | + rendering: |
| 68 | + heading_level: 4 |
| 69 | +::: botcity.web.browsers.firefox.default_capabilities |
| 70 | + rendering: |
| 71 | + heading_level: 4 |
| 72 | + |
| 73 | +### Edge |
| 74 | +::: botcity.web.browsers.edge.default_options |
| 75 | + rendering: |
| 76 | + heading_level: 4 |
| 77 | +::: botcity.web.browsers.edge.default_capabilities |
| 78 | + rendering: |
| 79 | + heading_level: 4 |
0 commit comments