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**

1 Answer 1

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");
Sign up to request clarification or add additional context in comments.

3 Comments

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?")
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.
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 : captcha.telekom.hu/captcha/… but it gives me error:javax.imageio.IIOException: Can't get input stream fro...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.