Home > Mobile >  How to set default download path for chrome using selenium webdriver in ubuntu 20.04?
How to set default download path for chrome using selenium webdriver in ubuntu 20.04?

Time:01-30

I am trying to save a zip file by using download as option inside a specific folder. I found a way by which I am able to download the file. But the problem where I am stuck is while setting default path in ubuntu it is taking frontslash /, whereas in windows it takes backslash \.

Below is my code which i am using to set the default path.

HashMap<String, Object> hashmap = new HashMap<>();
String  defaultPath = System.getProperty("user.dir")  "\\src\\main\\resources";
hashmap.put("download.default_directory", defaultPath);
options.setExperimentalOption("prefs", hashmap);

During execution the default path is set as below in Ubuntu 20.04 which causing the test case to fail as the file is downloaded in the default location.

/home/user/git/ui-automation\src\main\resources 

Can someone help me to resolve this issue ?

CodePudding user response:

You can use the Paths class to resolve file paths that are normalized to the underlying host system:

import java.nio.file.Paths 

String userDir = System.getProperty("user.dir");
Strung defaultPath = Paths.get(userDir, "src", "main", "resources").toString();
  • Related