[英]C# Geckodriver / Selenium 3.0 - Mozilla 47.0.1 stops itself
Hi I'm using Selenium Web Driver and Geckodriver to automate a task on Mozilla. 嗨,我正在使用Selenium Web驱动程序和Geckodriver在Mozilla上自动化任务。 When Geckodriver lauches an instance of Mozilla, there is no problem : 当Geckodriver启动Mozilla实例时,没有问题:
Problem : Mozilla closes itself after and Geckodriver re-launches Mozilla and does the same procedure (Account login, click on buttons ...) like an infinite loop. 问题:Mozilla在关闭后自行关闭,Geckodriver重新启动Mozilla并执行相同的过程(登录帐户,单击按钮...),就像无限循环一样。
I would like to correct it, any help would be greatly appreciated. 我想纠正它,任何帮助将不胜感激。 Thank you ! 谢谢 !
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
I am confused by your upload code. 我对您的上传代码感到困惑。 Have you used this strategy with success in other browsers? 您是否在其他浏览器中成功使用了此策略? Is this to upload a file through a browser window similar to this? 是否通过类似的浏览器窗口上传文件?
If so selenium handles file IO by simply calling SendKeys()
on the upload element. 如果是这样,Selenium只需在上载元素上调用SendKeys()
即可处理文件IO。 inputUpload.SendKey("C:/Test.xls");
I am unsure what would be causing the browser to close, but may I suggest using a testing framework such as NUnit? 我不确定会导致浏览器关闭的原因,但是我可以建议使用NUnit之类的测试框架吗? That way you can avoid the using
block and let the framework manage testSetup and tearDown. 这样,您可以避免using
块,并让框架管理testSetup和tearDown。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.