|
18 | 18 |
|
19 | 19 | #include "ClickElementCommandHandler.h"
|
20 | 20 | #include "errorcodes.h"
|
| 21 | +#include "logging.h" |
21 | 22 | #include "../Browser.h"
|
22 | 23 | #include "../Element.h"
|
23 | 24 | #include "../Generated/atoms.h"
|
@@ -55,6 +56,10 @@ void ClickElementCommandHandler::ExecuteInternal(const IECommandExecutor& execut
|
55 | 56 | ElementHandle element_wrapper;
|
56 | 57 | status_code = this->GetElement(executor, element_id, &element_wrapper);
|
57 | 58 | if (status_code == WD_SUCCESS) {
|
| 59 | + if (this->IsFileUploadElement(element_wrapper)) { |
| 60 | + response->SetErrorResponse(ERROR_INVALID_ARGUMENT, "Cannot call click on an <input type='file'> element. Use sendKeys to upload files."); |
| 61 | + return; |
| 62 | + } |
58 | 63 | if (executor.input_manager()->enable_native_events()) {
|
59 | 64 | if (this->IsOptionElement(element_wrapper)) {
|
60 | 65 | std::string option_click_error = "";
|
@@ -238,4 +243,22 @@ int ClickElementCommandHandler::ExecuteAtom(
|
238 | 243 | return status_code;
|
239 | 244 | }
|
240 | 245 |
|
| 246 | +bool ClickElementCommandHandler::IsFileUploadElement(ElementHandle element) { |
| 247 | + CComPtr<IHTMLInputFileElement> file; |
| 248 | + element->element()->QueryInterface<IHTMLInputFileElement>(&file); |
| 249 | + CComPtr<IHTMLInputElement> input; |
| 250 | + element->element()->QueryInterface<IHTMLInputElement>(&input); |
| 251 | + CComBSTR element_type; |
| 252 | + if (input) { |
| 253 | + input->get_type(&element_type); |
| 254 | + HRESULT hr = element_type.ToLower(); |
| 255 | + if (FAILED(hr)) { |
| 256 | + LOGHR(WARN, hr) << "Failed converting type attribute of <input> element to lowercase using ToLower() method of BSTR"; |
| 257 | + } |
| 258 | + } |
| 259 | + bool is_file_element = (file != NULL) || |
| 260 | + (input != NULL && element_type == L"file"); |
| 261 | + return is_file_element; |
| 262 | +} |
| 263 | + |
241 | 264 | } // namespace webdriver
|
0 commit comments