Close download bar - selenium

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?

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

Related

open a link in new tab in selenium

I am trying to open a link in new tab.
Trial1
Actions action = new Actions(Driver).KeyDown(Keys.Control).KeyDown(Keys.Shift).Click(FindElement(xxx).KeyUp(Keys.Control).KeyUp(Keys.Shift);
action.Build().Perform();
This code opens the link in new tab at the same time opens another blank window
Trial2 - right click the link and choose the first option "open link new tab"
action.ContextClick(FindElement(xxx).SendKeys(Keys.ArrowDown).SendKeys(Keys.Enter).Build().Perform();
This opens the link in new window instead of new tab
So what you need to do is first open a new tab using JS executor:
((JavascriptExecutor)driver).executeScript("window.open()");
or
((JavascriptExecutor)driver).executeScript("window.open('the new link here', '_blank')");
If you did not use the secon method continue with the following: switch to the new window and navigate to the link
driver.switchTo().window(here the window handle);
driver.get("here is the link");

How to close popup windows in Selenium?

I'm doing a test with java and popup windows appear (ads) and I do not know how to close them to continue with my test.
I have to click on a button but I change the focus to the window.
The url is www.orbitz.com
Please help!
orbitz
Java solution:
//switch to opened tab
ArrayList<String> tabs_windows = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs_windows.get(1));
//close current tab and switch driver back to original
((JavascriptExecutor)driver).executeScript("close();");
for (String winHandle : driver.getWindowHandles()) {
driver.switchTo().window(winHandle);
}
I haven't tested this for a while, but in different browsers getWindowHandles() used to return different orders for the tabs. Not sure if you can assume 0 is the first tab for all browsers. Change the index accordingly, or store the current handle before popup, and close all that don't match that.

How to close pop up window, when there is no XPath for close button?

When I clicked on a some link, the popup window is opened on new browser.
I want to close that pop up window, but I am unable to find out the locator.
How to close window, when it is opened as popup in Selenium?
Use this this,it worked for me
// Before new window
String currentWindow=driver.getWindowHandle();
//After window new open
Set<String> handles=driver.getWindowHandles();
//to make set having only one single/current window value
handles.remove(currentWindow);
String[] handlesArray = handles.toArray(new String[handles.size()]);
driver.switchTo().window(handlesArray[0]).close();

Selenium IDE window focus in Internet Explorer

I'm using selenium IDE and webdriver to test a web page in Internet Explorer. I discovered a while back that IE will not fully accept commands from Selenium if it's not the window in focus. For example, if the Selenium IDE window is in focus, and the command is to click a button in IE, the button will push down, but it won't let go.
With that in mind, my test involves popping up a window, doing a few things in it, leaving it open and returning to the null window to do a few things, then returning to the popup for a few more commands.
Is there a way I can make the null window come forward (over the popup) when I need to execute the commands for the null window? And then vice versa, can I make the popup then come forward when I need to return to it? I tried using windowFocus, but that did not work.
Use the SwitchTo() method and the TargetLocator Interface in Selenium.
A really simple example would look like this:
// Switch to new window
public String SwitchToNewWindow()
{
// Get the original window handle
String winHandleBefore = driver.getWindowHandle();
foreach(String winHandle in driver.getWindowHandles())
{
driver.switchTo().window(winHandle);
}
return Constants.KEYWORD_PASS;
}
// Switch back to original window
public String switchwindowback()
{
String winHandleBefore = driver.getWindowHandle();
driver.close();
//Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);
//continue with original browser (first window)
return Constants.KEYWORD_PASS;
}
I remembered that webdriver sometimes acts differently than running non-webdriver tests. It turns out that using windowSelect followed by windowFocus switches between windows when running webdriver tests.

How do I use chrome driver to click a button in a frame in a pop up window, then get back to my original window?

I would, naively it seems, expect this code to click a button that opens a popup, switch to the popup, find the results frame (thanks sales force!) click a button there then finaly switch focus back to the original page.
Instead I get a 500 server error on the final switch to 'home'.
What should I be doing? I am using ChromeDriver 19.0.1068.0
Thanks
PageHelper.CountryButton.Click();
var home = _driver.CurrentWindowHandle;
foreach (var window in _driver.WindowHandles)
{
if (_driver.SwitchTo().Window(window).Title.Contains("Search"))
{
_driver.SwitchTo().Frame("resultsFrame");
PageHelper.Country.Click();
break;
}
}
_driver.SwitchTo().Window(home);
I have no solution to this but I expect it is related to this issue
http://code.google.com/p/selenium/issues/detail?id=1167