嗨,我正在使用 Selenium Web Driver 和 Geckodriver 来自动执行 Mozilla 上的任务。当 Geckodriver 启动 Mozilla 实例时,没有问题:
- 帐号登录
- 点击按钮
- 导入文件(之后出现问题)。
- 下一个代码未编译。
问题:Mozilla 在 Geckodriver 重新启动 Mozilla 后自行关闭,并执行相同的过程(帐户登录、单击按钮...),就像一个无限循环。
我想更正它,任何帮助将不胜感激。谢谢 !
FirefoxProfile fox = new FirefoxProfile();
fox.SetPreference("browser.helperApps.neverAsk.saveToDisk", "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;");
fox.SetPreference("browser.helperApps.alwaysAsk.force", false);
fox.SetPreference("browser.download.folderList", 2);
fox.SetPreference("browser.download.dir", temp);
using (var driver = new FirefoxDriver(new FirefoxBinary(@"C:\Mozilla Firefox\firefox.exe"), fox))
{
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("//");
//Click on buttons without problems
System.Threading.Thread.Sleep(5000);
//Import file
var inputUpload = driver.FindElementById("uploadedPrevisionsFileId-button");
inputUpload.Click();
//I put Thread.Sleep to wait until the element appears
System.Threading.Thread.Sleep(3000);
SendKeys.Send("C:/Test.xls");
SendKeys.Send("{ENTER}");
//HERE, Mozilla stops but I can see the file has been imported
//Code ...
}
//And it restarts a new instance of Mozilla which does the same thing