简体   繁体   English

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

[英]Selenium web driver fill fields save output

I am absolutly new in selenium so sorry for the noob question. 我在硒中绝对是新的,所以对于noob问题感到抱歉。 But i couldnt find it in google. 但我无法在谷歌找到它。 So, I have a simple javacode : 所以,我有一个简单的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. 网页顺便说一句:[link] [1]我想填写左框。 To do so I want some selenium commands : s.fill(and here xpath, "fill with text") 为此,我想要一些selenium命令:s.fill(这里是xpath,“填充文本”)

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 对于xpath,我使用firefox插件并找到xpath:我无法发布图片,因此有一个链接: 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. 然后我会得到somecapthca破坏它在当地的未来,但如果oyu有建议我采取它:)无论如何,我需要下载图片并手动填写它。 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? 然后点击“ keresés ”按钮xpoath:id('searchByName')/ x:输入[2]但是在第一步我失败了,我不能检查是seleinum(JAVA)填满了字段?

** So the main question how can i fill the fields, download a pics through xpath in selenium (JAVA), than save the output** **所以主要问题我如何填写字段,通过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**

You can use Selenium and Java to save an image like so, 您可以使用Selenium和Java来保存这样的图像,

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, 如果你想从xpath获取图像src来下载src这样做,

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

You've got to skip captcha in your tests. 你必须在测试中跳过验证码。 Ask developers to prepare a parameter that will be passed to application in URL, this will allow you to use application without filling captcha. 要求开发人员准备一个将传递给URL中的应用程序的参数,这将允许您在不填写验证码的情况下使用应用程序。

That's how its done in my tests. 这就是我在测试中的表现。

Unless you are testing captcha functionality of course :) 除非您正在测试验证码功能当然:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM