Skip to content

Commit 5a33e73

Browse files
committed
Add method: "self.show_file_choosers()"
1 parent ea0c138 commit 5a33e73

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

help_docs/method_summary.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,8 @@ self.remove_elements(selector, by=By.CSS_SELECTOR)
305305
self.ad_block()
306306
# Duplicates: self.block_ads()
307307

308+
self.show_file_choosers()
309+
308310
self.get_domain_url(url)
309311

310312
self.get_beautiful_soup(source=None)

seleniumbase/fixtures/base_case.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3498,6 +3498,29 @@ def ad_block(self):
34983498
except Exception:
34993499
pass # Don't fail test if ad_blocking fails
35003500

3501+
def show_file_choosers(self):
3502+
"""Display hidden file-chooser input fields on sites if present."""
3503+
css_selector = 'input[type="file"]'
3504+
try:
3505+
self.show_elements(css_selector)
3506+
except Exception:
3507+
pass
3508+
css_selector = re.escape(css_selector) # Add "\\" to special chars
3509+
css_selector = self.__escape_quotes_if_needed(css_selector)
3510+
script = (
3511+
"""var $elements = document.querySelectorAll('%s');
3512+
var index = 0, length = $elements.length;
3513+
for(; index < length; index++){
3514+
the_class = $elements[index].getAttribute('class');
3515+
new_class = the_class.replaceAll('hidden', 'visible');
3516+
$elements[index].setAttribute('class', new_class);}"""
3517+
% css_selector
3518+
)
3519+
try:
3520+
self.execute_script(script)
3521+
except Exception:
3522+
pass
3523+
35013524
def get_domain_url(self, url):
35023525
self.__check_scope()
35033526
return page_utils.get_domain_url(url)

0 commit comments

Comments
 (0)