我正在尝试将文件上传到div标签。它没有类型作为文件输入。因此,请人们建议使用文件路径的sendkey,请检查我的完整问题。
我有这样的标签。
我尝试了带有find元素的sendkeys并从中上传本地文件。这对我没有用。
这是我尝试过的。
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
ObjectNode content = mapper.createObjectNode();
rootNode.set("someContent", content);
content.put("somekey","someval");
... lots more nested objects created here...
这给我这样的错误。
GlobalVariables.chromeDriver_Main.findElement(By.xpath("//*[@id=\"card-uploader\"]"))
.sendKeys("C:\\Users\\Dhaval Bhimajiyani\\Documents\\Lightshot\\Screenshot_207.png");
我需要了解如何将文件上传到此div标签。没有输入类型作为文件。
感谢您的提前答复。
答案 0 :(得分:0)
尝试一下。
# get the button element
ele = driver.find_element_by_id("card-uploader")
# add a hidden file input ( might have to change the onchange event based on the events associated to the button in above line as you don't have a form)
driver.execute_script("var x= document.createElement('INPUT');x.setAttribute('type', 'file'); x.setAttribute('onchange','this.form.submit()');x.setAttribute('hidden', 'true'); arguments[0].appendChild(x);",ele)
# send the file path here ( this should upload the file)
driver.find_element_by_xpath("//input[@type='file']").send_keys("C:\\Users\\Dhaval Bhimajiyani\\Documents\\Lightshot\\Screenshot_207.png")