如何在Selenium-ide 3-7-4中上传文件 [英] How to upload file in selenium-ide 3-7-4

查看:110
本文介绍了如何在Selenium-ide 3-7-4中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们需要切换到第二个窗口 选择标题在这种情况下不起作用,我们该怎么做在此处输入图片描述

we need to switch to the second window select title is not working in this case how can we do that pleaseenter image description here

推荐答案

1)使用sendkey,我们可以发送文件路径名:-

这是执行文件上传的最基本技术.使用ID或名称获取文件上传元素.然后调用Webdriver的sendKeys()方法来设置要上传的文件的值.

It’s the most basic technique to perform the upload of a file.Get the file upload element either by using the Id or Name. And call the Webdriver’s sendKeys() method to set the value of the file to upload.

在WebDriver中上传文件时,请记住以下两点

Remember following two things when uploading files in WebDriver

1)无需模拟浏览"按钮的单击. WebDriver会自动在<input type="file">元素的文件选择文本框中输入文件路径.

1)There is no need to simulate the clicking of the "Browse" button. WebDriver automatically enters the file path onto the file-selection text box of the <input type="file"> element.

2)在Java IDE中设置文件路径时,请使用正确的转义符作为反斜杠.

2)When setting the file path in your Java IDE, use the proper escape character for the back-slash.

尝试一下:-

     WebDriver driver = new FirefoxDriver();

     // Put an Implicit wait, 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

     // Launch the URL
     driver.get("http://toolsqa.com/automation-practice-form");

     WebElement element = driver.findElement(By.id("photo"));

     element.sendKeys("/home/savera9/Desktop/test.jpg");

还有另一种上传文件的技术,请检查

There is another techniques also for uploading file please check this

2)使用机器人课程:-

    driver.findElement(By.xpath("Path of that element")).click();

    StringSelection strSel = new StringSelection("upload file path");
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(strSel, null);


    Robot robot = new Robot();

    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);

    Thread.sleep(3000);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

3)使用AutoIT:-

AutoIT通过将控件从Selenium Web驱动程序转移到AutoIT来帮助上传文件.我们需要从程序中显式调用AutoIT脚本.单击上载按钮后,焦点将移至AutoIT,它将执行将用于上载文件的语句.

AutoIT helps to upload files by transferring the control from Selenium web driver to AutoIT. We need to explicitly call the AutoIT script from our program. After clicking on upload button, the focus will be moved to AutoIT and it will execute the statements which will be used to upload files.

4)使用Sikuli:-

Sikuli 是一种开源的图形用户界面自动化工具. Sikuli将用于自动执行您可以在屏幕上查看的任何内容.它使用图像识别来与GUI元素对话.如果无法轻松访问GUI的源代码,这是获得适当响应的最佳方法之一.

Sikuli is an open source Graphical User Interface automation tool. Sikuli will be used to automate anything that you can view on the screen. It uses image recognition to speak with the GUI elements. When there is no easy access to a GUI’s source code this is one of the best ways to get the appropriate response.

还有另一种通过此链接上传文件的方法 https://www.evoketechnologies.com/blog/selenium-automation-uploading-multiple-files-via-web-browsers-file-dialog/

There is another ways also to upload file go through this link https://www.evoketechnologies.com/blog/selenium-automation-uploading-multiple-files-via-web-browsers-file-dialog/

这篇关于如何在Selenium-ide 3-7-4中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆