getWindowHandles() not working in firefox 58.The focus remains on parent tab and does not transfer to next tab

getWindowHandles() works pretty fine but before invoking getWindowHandles() you have to induce WebDriverwait as follows : System.setProperty(“webdriver.gecko.driver”, “C:\\Utility\\BrowserDrivers\\geckodriver.exe”); WebDriver driver= new FirefoxDriver(); driver.get(“https://www.facebook.com/”); String parent= driver.getWindowHandle(); System.out.println(“Parent Window is”+parent); driver.findElement(By.linkText(“Data Policy”)).click(); WebDriverWait wait = new WebDriverWait(driver,5); wait.until(ExpectedConditions.numberOfWindowsToBe(2)); Set<String> s1= driver.getWindowHandles(); for(String s2:s1) { if(!parent.equalsIgnoreCase(s2)) { driver.switchTo().window(s2); Thread.sleep(5000); System.out.println(driver.getWindowHandle()); System.out.println(“get title of window”+driver.getTitle()); } } Console … Read more

Selenium Switch Tabs

A few words about Tab/Window switching/handling: Always keep track of the Parent Window handle so you can traverse back later if required as per your usecase. Always use WebDriverWait with expected_conditions as number_of_windows_to_be(num_windows) before switching between Tabs/Windows. Always keep track of the Child Window handles so you can traverse whenever required. Always use WebDriverWait with … Read more

Check if any alert exists using selenium with python

What I do is to set a conditional delay with WebDriverWait just before the point I expect to see the alert, then switch to it, like this: from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.common.exceptions import TimeoutException browser = webdriver.Firefox() browser.get(“url”) browser.find_element_by_id(“add_button”).click() try: WebDriverWait(browser, 3).until(EC.alert_is_present(), ‘Timed out … Read more

Best way to keep track and iterate through tabs and windows using WindowHandles using Selenium

You are pretty correct when you say: WindowHandles would be sorted like the oldest windows first and the newest windows last. But this is not the case: It is totaly random! In a discussion, Simon clearly mentioned that: While the datatype used for storing the list of handles may be ordered by insertion, the order … Read more