简体   繁体   English

如何使用Java在Selenium Webdriver中输入类型不是“文件”时上传照片

[英]How to upload Photo when Input type is not 'File' in Selenium Webdriver by Using Java

<span>
<span class="glyphicon glyphicon-plus avatarUploacIcon"></span>
Upload profile image</span>

i am using below code.. 我正在使用下面的代码..

 WebElement uploading=driver.findElement(By.cssSelector("div[class='form_advanced_wrapper my-events_host_wrapper'] span[class='glyphicon glyphicon-plus avatarUploacIcon']"));
         uploading.click();
         uploading.sendKeys("C:\pic.jpg");

I have reached proper direction but not upload any image, please help my I have applied more and more syntax but not success to upload image because my type is not 'File'. 我已经达到正确的方向,但没有上传任何图像,请帮助我,我已经应用了越来越多的语法,但没有成功上传图像,因为我的类型不是'文件'。 If any one use image upload without File type , Please share me how to use this ............... 如果任何人使用没有文件类型的图片上传,请分享我如何使用这个...............

    Finally, I  got it answer  when Input Type is not "File"....
Thanks Everyone Who suggest me......



public static void main(String[] args) throws InterruptedException
            {
                WebDriver driver = new FirefoxDriver();
                String appUrl = "http://demo.theupbeetkitchen.com/";
                driver.get(appUrl);
                driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
                driver.findElement(By.id("customLogin")).click();
                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                 String newSet = driver.getWindowHandle();
                 driver.switchTo().window(newSet);   
                 driver.findElement(By.id("login_div")).click(); 
                 driver.findElement(By.id("ID")).sendKeys("mr.saurabh.gupta92@gmail.com");
                 driver.findElement(By.id("Password")).sendKeys("123456");
                 driver.findElement(By.id("loginButton")).submit();
                 driver.findElement(By.id("customWelcome Chef Saurabh Gupta!")).click();
                 driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
                 driver.findElement(By.className("btn")).click();
                 driver.findElement(By.id("photoVideoPage")).click();
                 Thread.sleep(2000);
                 WebElement uploading=driver.findElement(By.cssSelector("div[class='form_advanced_wrapper my-events_host_wrapper'] span[class='glyphicon glyphicon-plus avatarUploacIcon']"));
                 uploading.click();
                 uploadFile("C:\\pic.jpg");
                 System.out.println("Successfully Done...........");
            }
            public static void uploadFile(String fileLocation) 
            {
                try
                {
                    setClipboardData(fileLocation);
                    Robot robot = new Robot();  
                    robot.keyPress(KeyEvent.VK_CONTROL);
                    robot.keyPress(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_V);
                    robot.keyRelease(KeyEvent.VK_CONTROL);
                    robot.keyPress(KeyEvent.VK_ENTER);
                    robot.keyRelease(KeyEvent.VK_ENTER);
                    robot.delay(2000);
                    robot.keyPress(KeyEvent.VK_ENTER);

                } 
                catch (Exception exp) 
                    {
                        exp.printStackTrace();
                    }
            }
            private static void setClipboardData(String string) 
            {
                // TODO Auto-generated method stub
                 StringSelection stringSelection = new StringSelection(string);
                   Toolkit.getDefaultToolkit().getSystemClipboard().setContents(stringSelection, null);

            }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium Webdriver中的“上传图像按钮”上传文件/照片 - How to Upload File/Photo using “Upload Image Button” in Selenium Webdriver 如何在Java中使用Selenium WebDriver上传文件 - How to upload file using Selenium WebDriver in Java 如何在没有“输入”元素的情况下在 Selenium WebDriver 中上传文件 - How to upload a file in Selenium WebDriver with no 'input' element 在Mac上使用Selenium WebDriver和Java进行文件上载 - File Upload Using Selenium WebDriver and Java on a Mac 使用Java和Selenium Webdriver上传文件 - Upload file using Java and Selenium Webdriver 在Java中使用Selenium WebDriver无法上传文件 - failed to upload a file using selenium webdriver in Java 如何使用Selenium Webdriver + Java确定Web元素的输入类型? - How to determine the input type of a web element using Selenium Webdriver + Java? 当元素不是选择类型输入时,如何使用Selenium Webdriver Java从下拉列表中获取所有选项值? - how to get all option values from dropdown using selenium webdriver java when the element is not a select type input? 如何使用Selenium Webdriver上传文件? - How to upload file using Selenium Webdriver? 如何使用Selenium和Java通过类型为“ hidden”的“ input”元素上传文件? - How to upload file through an 'input' element with type=“hidden” using Selenium and Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM