如何处理Safari WebseleniumWebdriver的文件下载

我想知道它有Safari Selenium

Webdriver所需的任何功能或选项设置,可以将文件保存到特定位置,就像我们为firefox驱动程序所做的那样。

还想禁用文件保存对话框的弹出窗口。

问候,Himanshu

回答:

您可以检查以下链接。dataDir你工作吗,但不确定

http://code.google.com/p/selenium/wiki/DesiredCapabilities#Safari_specific

试试这个

Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);

CommandExecutor executor = new SeleneseCommandExecutor(sel);

DesiredCapabilities dc = new DesiredCapabilities();

dc.setCapability("safari.options.dataDir", "your folder path");

WebDriver browser = new RemoteWebDriver(executor, dc);

WebElement link = driver.findElement(By.xpath("myxpath"));

clickAndSaveFileIE(link);

public static void clickAndSaveFileIE(WebElement element) throws InterruptedException{

try {

Robot robot = new Robot();

//get the focus on the element..don't use click since it stalls the driver

element.sendKeys("");

//simulate pressing enter

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

//wait for the modal dialog to open

Thread.sleep(2000);

//press s key to save

robot.keyPress(KeyEvent.VK_S);

robot.keyRelease(KeyEvent.VK_S);

Thread.sleep(2000);

//press enter to save the file with default name and in default location

robot.keyPress(KeyEvent.VK_ENTER);

robot.keyRelease(KeyEvent.VK_ENTER);

} catch (AWTException e) {

e.printStackTrace();

}

以上是 如何处理Safari WebseleniumWebdriver的文件下载 的全部内容, 来源链接: utcz.com/qa/402558.html

回到顶部