如何在Katalon for Chrome浏览器中处理或抑制警告“此类文件可能会损害您的计算机。你还想保留吗?“

问题描述 投票:1回答:2

我想在运行我的Katalon脚本时禁止标题中提到的上述警报。

附上相同的屏幕截图:

enter image description here

selenium webdriver katalon-studio
2个回答
0
投票

我们可能必须在安全模式下运行chromedriver。请尝试下面的代码

System.setProperty("webdriver.chrome.driver", "C:/chromedriver/chromedriver.exe");
        String downloadFilepath = "D:/MyDeskDownload";
        HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
        chromePrefs.put("profile.default_content_settings.popups", 0);
        chromePrefs.put("download.default_directory", downloadFilepath);
        chromePrefs.put("safebrowsing.enabled", "true"); 
        ChromeOptions options = new ChromeOptions();
        options.setExperimentalOption("prefs", chromePrefs);
        DesiredCapabilities cap = DesiredCapabilities.chrome();
        cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
        cap.setCapability(ChromeOptions.CAPABILITY, options);
        WebDriver driver = new ChromeDriver(cap);

0
投票

您可以将浏览器设置为自动下载文件。以下摘自Katalon forum

首先添加Chrome偏好设置:

HashMap<String, Object> chromePrefs = new HashMap<String, Object>()
chromePrefs.put("download.default_directory", downloadPath)
chromePrefs.put("download.prompt_for_download", false)

然后指定ChromeDriver的路径并添加实验选项:

System.setProperty("webdriver.chrome.driver", "DriverFactory.getChromeDriverPath()")
ChromeOptions options = new ChromeOptions()
options.setExperimentalOption("prefs", chromePrefs)

注意:

您需要导入以下内容(或按CTRL + SHIFT + O进行自动导入):

import org.openqa.selenium.WebDriver
import org.openqa.selenium.chrome.ChromeDriver
import com.kms.katalon.core.webui.driver.DriverFactory
© www.soinside.com 2019 - 2024. All rights reserved.