相关疑难解决方法(0)

如何在使用chrome driver/firefox驱动程序时更改Webdriver中的文件下载位置

我试图通过在特定文件夹中使用另存为选项来保存图像.我找到了一种方法,通过另存为选项,我可以右键单击要保存的图像.但我遇到的问题是在获取os窗口后询问保存文件的位置我无法发送所需的位置,因为我不知道该怎么做.我经历了在这个论坛上提出的类似问题但到目前为止他们没有帮助.

代码是 -

对于Firefox-

public class practice {

 public void pic() throws AWTException{
     WebDriver driver;

     //Proxy Setting     
        FirefoxProfile profile = new FirefoxProfile();
        profile.setAssumeUntrustedCertificateIssuer(false);
        profile.setEnableNativeEvents(false);
        profile.setPreference("network.proxy.type", 1);
        profile.setPreference("network.proxy.http", "localHost");
        profile.setPreference("newtwork.proxy.http_port",3128);

        //Download setting
        profile.setPreference("browser.download.folderlist", 2);
        profile.setPreference("browser.helperapps.neverAsk.saveToDisk","jpeg");
        profile.setPreference("browser.download.dir", "C:\\Users\\Admin\\Desktop\\ScreenShot\\pic.jpeg");
        driver = new FirefoxDriver(profile);

        driver.navigate().to("http://stackoverflow.com/users/2675355/shantanu");
        driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"));
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(By.xpath("//*[@id='large-user-info']/div[1]/div[1]/a/div/img"))).perform();
        action.contextClick().perform();
        Robot robo = new Robot();
        robo.keyPress(KeyEvent.VK_V);
        robo.keyRelease(KeyEvent.VK_V);
    // Here I am getting the os window but don't know how to send the desired location
    }//method   
}//class
Run Code Online (Sandbox Code Playgroud)

对于铬 -

public class practice …
Run Code Online (Sandbox Code Playgroud)

java automated-tests file-upload download selenium-webdriver

19
推荐指数
3
解决办法
6万
查看次数

如何设置InternetExplorerDriver下载目录?

我们使用Selenium从我们的Web应用程序测试文件下载.目前我们正在使用Firefox,将其设置为所需的下载目录,并确保没有弹出对话框,下载文件时不需要用户交互.

对于FirefoxDriver,我们这样做:

File downloadDir = ...;
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.download.dir", downloadDir.getAbsolutePath());
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "...");
WebDriver driver = new FirefoxDriver(profile);
Run Code Online (Sandbox Code Playgroud)

为InternetExplorerDriver做些什么来达到同样的效果?我找不到InternetExplorerProfile,也找不到DesiredCapabilities中的开关.

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("???", "???");
WebDriver driver = new InternetExplorerDriver(capabilities);
Run Code Online (Sandbox Code Playgroud)

selenium internet-explorer selenium-webdriver

8
推荐指数
1
解决办法
4727
查看次数