Selenium 关闭下载栏

Selenium 关闭下载栏,selenium,selenium-webdriver,selenium-chromedriver,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在使用Java和Selenium编写一个测试。在我测试的某个地方,我下载了一个文件,但需要点击chrome浏览器页面底部下载栏下的一个按钮。我搜索了很多,但唯一的解决办法是这不是我的情况,因为我没有卷轴 我还使用: action.sendKeys(Keys.CONTROL+ "j").build().perform(); action.keyUp(Keys.CONTROL).build().perform(); Thread.sleep(500); ArrayList<

我正在使用Java和Selenium编写一个测试。在我测试的某个地方,我下载了一个文件,但需要点击chrome浏览器页面底部下载栏下的一个按钮。我搜索了很多,但唯一的解决办法是这不是我的情况,因为我没有卷轴

我还使用:

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);
action.sendKeys(key.CONTROL+j”).build().perform();
action.keyUp(Keys.CONTROL).build().perform();
睡眠(500);
ArrayList tabs2=新的ArrayList(driverChrome.getWindowHandles());
driverChrome.switchTo().window(tabs2.get(1));
睡眠(500);
driverChrome.close();
driverChrome.switchTo().window(tabs2.get(0));
睡眠(500);
但它不会打开下载页面


无论如何,我可以关闭下载栏吗?

这种方法对我也不起作用,但我开发了一种解决方法。我在一个新窗口中做任何下载测试,然后关闭下载窗口,原来的窗口没有下载栏。它必须是一个新窗口,如果你做了一个新的标签,它会转移过来,为了得到这个,我使用JavaScript。切换到新窗口,运行下载测试,完成后切换到原始窗口

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