Can't browse file using webdriver.
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
driver.findElement(By.id("1434461513889_57_7_input.file")).sendKeys("C:\\PDF_V1_COL88810_6L_Frangipani_TL_Fr_P1211089.pdf");
Have this error:
NoSuchElementException: Unnable to locate element: {"method":"id","selector":"BatchUploadPlugin_57_fileupload"}
From the screenshot you have given, I can see the concerned element is in an iframe.
(Check the second bar in the developer tools below the bar containing: Inspector, Console,etc. You will note the iframe#iframe_1434526152814_57_7. ).
Hence, you weren't able to send the path to it.
In order to send the path for upload, you need to switch to the frame first and then send the path to the element "Browse" for upload.
For switching frame, you can use the below code (The frame id that I can see from the screenshot, is iframe_1434526152814_57_7
which I can safely presume to be dynamic and can't use as ID of the frame to switch-to. So, I am assuming there is only 1 frame in the page, hence the code.):
driver.switchTo().frame(0);
Then, send the path to the element using the below code:
driver.findElement(By.xpath("//input[@name='userfile']")).sendKeys("C:\\PDF_V1_COL88810_6L_Frangipani_TL_Fr_P1211089.pdf");
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加