1

I am absolutly new in selenium so sorry for the noob question. But i couldnt find it in google. So, I have a simple javacode :

 public static void main(String[] args) throws Exception {
    // The Firefox driver supports javascript 
    WebDriver driver = new FirefoxDriver();

    // Go to the Google Suggest home page
    driver.get("http://tudakozo.telekom.hu/main?xml=main&xsl=main");

    // Enter the query string "Cheese"
    WebElement query = driver.findElement(By.xpath("id('searchByName')/x:input[2]"));

the webpage btw : [link][1] I want to fill the left boxes. To do so I want some selenium commands : s.fill(and here xpath, "fill with text")

For xpath i use firefox plugin and find xpath: i cant post image so heres a link : http://tinypic.com/view.php?pic=5poglt&s=8#.U_sw-vl_tVY

Then I will get somecapthca breaker Its in the local future but if oyu have suggestion i take it :) Anyway than i need to download the pics and manually fill it. Than click the "keresés" button xpoath: id('searchByName')/x:input[2] but in the first step i fail, and i cant check that is the seleinum (JAVA) filled the field?

** So the main question how can i fill the fields, download a pics through xpath in selenium (JAVA), than save the output**

example : *név*(name) :first field : **Szabó István** and
 *Település*(city)/the field where there is a little pink text/ : **Gyula**
SüniÚr
  • 826
  • 1
  • 16
  • 33

1 Answers1

2

You can use Selenium and Java to save an image like so,

string url = "yourimage.png";
BufferedImage bufImgOne = ImageIO.read(url);
ImageIO.write(bufImgOne, "png", new File("test.png"));

As far as filling out a form,

driver.findElement(By.id("yourID")).sendKeys("text you need to send");

If you're looking to get the image src from an xpath to download that src do this,

WebElement img = driver.findElement(By.id("foo")); // or xpath whichever you prefer
String src = img.getAttribute("src");
Chris Hawkes
  • 11,923
  • 6
  • 58
  • 68
  • but i dont have link only maybe xpath, some id-ed->following sibling->idk elemetn->and heres the link. can i download through link/xpath? and the same q what kind of xpath can i use for by.xpath("//xpath?") – SüniÚr Aug 25 '14 at 13:05
  • I just edited my answer basically use xpath or by id, class etc... to get the src attribute that you can then use to download the image. – Chris Hawkes Aug 25 '14 at 13:11
  • hi i tried to download a file like you said: WebElement img = driver.findElement(By.xpath("//form[@id='searchByName']/table/tbody/tr/td/img")); // or xpath whichever you prefer String src = img.getAttribute("src"); System.out.println(src); URI uri = new URI(src); URL url = uri.toURL(); BufferedImage bufImgOne = ImageIO.read(url); ImageIO.write(bufImgOne, "jph", new File("test.png")); its get the link : https://captcha.telekom.hu/captcha/m2AE1F34B3CAC04365E00B95E3D79C5551.jpg but it gives me error:javax.imageio.IIOException: Can't get input stream fro... – SüniÚr Aug 26 '14 at 08:44