It is about the images to be dragged and save it in a folder of a web application. To describe it a sample code is required.
package ZOVI;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.openqa.selenium.By;
public class StringSortExample {
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("https://zovi.com/");
driver.findElement(By.name("search")).click();
driver.findElement(By.name("search")).sendKeys("shoes");
driver.findElement(By.name("search")).sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
///List and drag images from a page
List<WebElement> allImg = driver.findElements(By.xpath("//img"));
try{
for(int i=0;i<allImg.size();i++)
{
String urlString=allImg.get(i).getAttribute("src");
System.out.println(urlString);
URL url = new URL(urlString);
BufferedImage image = ImageIO.read(url);
File file = new File("C:\\Users\\MY PC\\Desktop\\Screenshots\\numer.png"+i+".jpg");
ImageIO.write(image,"jpg", file);
}
}
catch(IOException e){
System.out.println("GET IMAGES" + e);
}
///List and drag images from a page
}
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
package ZOVI;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import org.openqa.selenium.By;
public class StringSortExample {
public static void main(String[] args) throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("https://zovi.com/");
driver.findElement(By.name("search")).click();
driver.findElement(By.name("search")).sendKeys("shoes");
driver.findElement(By.name("search")).sendKeys(Keys.ENTER);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
///List and drag images from a page
List<WebElement> allImg = driver.findElements(By.xpath("//img"));
try{
for(int i=0;i<allImg.size();i++)
{
String urlString=allImg.get(i).getAttribute("src");
System.out.println(urlString);
URL url = new URL(urlString);
BufferedImage image = ImageIO.read(url);
File file = new File("C:\\Users\\MY PC\\Desktop\\Screenshots\\numer.png"+i+".jpg");
ImageIO.write(image,"jpg", file);
}
}
catch(IOException e){
System.out.println("GET IMAGES" + e);
}
///List and drag images from a page
}
To know FAQ's in Interviews on Selenium ClickHere
To know more on SQL Queries Required For Testers ClickHere
Hi,
ReplyDeleteVery great tutorial. But how to load all the images where i hv to click Show more results button..Please tell me the code.