Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to use elem_send_keys to upload a query to a site? #37

Open
AntonioBergallo opened this issue Nov 22, 2024 · 1 comment
Open

how to use elem_send_keys to upload a query to a site? #37

AntonioBergallo opened this issue Nov 22, 2024 · 1 comment

Comments

@AntonioBergallo
Copy link

Hello! I'm not sure if elem_send_keys can handle external files. The example in the vintage is not very clear. For now, I wrote a javascript code to create a mock file, because I am not sure how to reach my local file using selenider.

js_code <- "
const fileInput = document.querySelector('input[type="file"]');
const dataTransfer = new DataTransfer();
const fileContent = RTTQ.SF11KS RTTQ.SF91KS RTTQ.SFA1KS RTTQ.SFB1KS RTTQ.SFC1KS RTTQ.SFE1KS RTTQ.SFF1KS RTTQ.SFG1KS RTTQ.SFH1KS RTTQ.SFJ1KS RTTQ.SFK1KS RTTQ.SFL1KS RTTQ.SFM1KS RTTQ.SFP1KS RTTQ.SFQ1KS RTTQ.SFU1KS RTTQ.SFV1KS;
const file = new File([fileContent], 'temp.sch', { type: 'application/x-sch' });
dataTransfer.items.add(file);
fileInput.files = dataTransfer.files;
fileInput.dispatchEvent(new Event('change'));
"
execute_js_expr(js_code)

@ashbythorpe
Copy link
Owner

elem_send_keys() does not work with file inputs. If you're using chromote, the CDP has a setInputFiles method, so you can probably do something like this:

session <- selenider_session()

open_url(...)

file_input <- s(...)

node_id <- get_actual_element(file_input)

session$driver$DOM$setFileInputFiles(
  files = list(...),
  backendNodeId = node_id
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants