Selenium Web驱动程序填充字段可保存输出

我绝对是selenium的新人,所以对于noob问题感到抱歉。 但我无法在谷歌找到它。 所以,我有一个简单的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]")); 

网页顺便说一句:[link] [1]我想填写左框。 为此,我想要一些selenium命令:s.fill(这里是xpath,“填充文本”)

对于xpath,我使用firefox插件并找到xpath:我无法发布图片,因此有一个链接: http ://tinypic.com/view.php?pic = 5poglt&s = 8#.U_sw-vl_tVY

然后我将得到somecapthca破坏它在当地的未来,但如果oyu有建议我接受:)无论如何,我需要下载图片并手动填写它。 然后点击“ keresés ”按钮xpoath:id(’searchByName’)/ x:输入[2]但是在第一步我失败了,我不能检查是seleinum(JAVA)填满了字段?

**所以主要的问题是如何填充字段,通过xlen(JAVA)中的xpath下载图片,而不是保存输出**

 example : *név*(name) :first field : **Szabó István** and *Település*(city)/the field where there is a little pink text/ : **Gyula** 

您可以使用Selenium和Java来保存这样的图像,

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

填写表格时,

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

如果你想从xpath获取图像src来下载src这样做,

 WebElement img = driver.findElement(By.id("foo")); // or xpath whichever you prefer String src = img.getAttribute("src"); 

你必须在测试中跳过validation码。 要求开发人员准备一个将传递给URL中的应用程序的参数,这将允许您在不填写validation码的情况下使用应用程序。

这就是我在测试中的表现。

除非您正在测试validation码function当然:)