[英]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.