Reputation: 11
How can we extract an image by id or class name in selenium by using java and display it in swing frame? We can extract text by
driver.findElement(By.id("Locator id")).getText();
But what about image?
I have checked with "href" and "src" (which actually is there), but no luck every time I am getting null value.
element = driver.findElement(By.id("my_image"));
String myImage = element.getAttribute("href");
System.out.println("Image url is: "+myImage);
image I want to extract is something like this
*div id="my_image" style="width: 300px; height: 57px;"> img width="300" height="57" src="https://www.myimage.com/image/xyz/image?c=85ikffkkgfl" alt="my image" style="display:block;"
Upvotes: 0
Views: 1722
Reputation: 1900
You can get the href from the image and load it on your swing component (or download it first and then load it onto swing).
You can get the href like this:
driver.findElement(By.id("Locator id")).getAttribute("href");
Upvotes: 0