Close download bar

混江龙づ霸主 提交于 2019-12-11 00:34:14

问题


I am using Java and Selenium to write a test. Somewhere in my test, I download a file but then need to click on a button under the download bar which appears at the bottom of the chrome browser page. I search a lot but the only solution was here which is not my case as I don't have a scroll.

I also use:

action.sendKeys(Keys.CONTROL+ "j").build().perform();
action.keyUp(Keys.CONTROL).build().perform();
Thread.sleep(500);        
ArrayList<String> tabs2 = new ArrayList<String> (driverChrome.getWindowHandles());
driverChrome.switchTo().window(tabs2.get(1));
Thread.sleep(500);
driverChrome.close();
driverChrome.switchTo().window(tabs2.get(0));
Thread.sleep(500);

but it doesn't open the download page.

Anyway that I can close the download bar?


回答1:


This method did not work for me either, but I developed a workaround. I do any download test in a new window, then close the download window, the original window does not have the download bar. It must be a new window, if you do a new tab it will transfer over, to get this I use JavaScript. Switch to the new window, run download test and then switch to the original window when done.

string javascript = $"$(window.open('', '_blank', 'location=yes'))";

((IJavaScriptExecutor)Driver).ExecuteScript(javascript); //create new window

Driver.SwitchTo().Window(Driver.WindowHandles.Last())); //switch to new window

//do download test here

Driver.Close(); //close created window

Driver.SwitchTo().Window(Driver.WindowHandles.First()); //back to original window with no download bar


来源:https://stackoverflow.com/questions/41598169/close-download-bar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!