My code is supposed to open a new window that goes from the login window to the main menu, module, reports, and finally the report name. The report name should be opened in the next tab.
Issue: The report name is not opening in a new tab; it's opening in a new window (blank window). Due to IE expiration within the organization, it redirects to Edge as per the legacy app code. We are not using a separate driver folder for this setup. Java - JDK 1.8 Selenium - 3.141.59 Tool - IntelliJ
public void launchBrowser() throws IOException {
String browser = properties.getProperty("Browser");
if (browser.equalsIgnoreCase("chrome")) {
// System.setProperty("webdriver.chrome.driver", "./Drivers/chromedriver.exe");
System.setProperty("wdm.proxy", wdmProxy);
System.setProperty("wdm.proxyUser", wdmProxyUser);
System.setProperty("wdm.proxyPass", wdmProxyPwd);
WebDriverManager.chromedriver().setup();
genericSteps.driver = new ChromeDriver();
} else if (browser.equalsIgnoreCase("ie")) {
// System.setProperty("webdriver.ie.driver", "./drivers/IEDriverServer.exe");
DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer();
capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
System.setProperty("wdm.proxy", wdmProxy);
System.setProperty("wdm.proxyUser", wdmProxyUser);
System.setProperty("wdm.proxyPass", wdmProxyPwd);
WebDriverManager.iedriver().setup();
genericSteps.driver = new InternetExplorerDriver(capabilities);
genericSteps.driver.manage().window().maximize();
genericSteps.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String test = properties.getProperty("URL");
genericSteps.driver.get(test);
}else if (browser.equalsIgnoreCase("edge")) {
// System.setProperty("webdriver.ie.driver", "./Drivers/IEDriverServer.exe");
// System.setProperty("webdriver.edge.driver", "./drivers/DriverServer.exe");
// System.setProperty("webdriver.edge.driver", "C:\\Users\\-------\\app\\drivers\\msedgedriver.exe");
EdgeOptions capabilities = new EdgeOptions();
System.setProperty("wdm.proxy", wdmProxy);
System.setProperty("wdm.proxyUser", wdmProxyUser);
System.setProperty("wdm.proxyPass", wdmProxyPwd);
WebDriverManager.edgedriver().setup();
genericSteps.driver = new EdgeDriver(capabilities);
genericSteps.driver.manage().window().maximize();
genericSteps.driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
genericSteps.driver.switchTo();
String test = properties.getProperty("URL");
genericSteps.driver.get(test);
}
}
/* Explicit wait for the Webelement on the page to be visible */
public void explicitWait(WebElement element, int timeToWaitInSec) {
WebDriverWait wait = new WebDriverWait(genericSteps.driver, timeToWaitInSec);
// wait.until(ExpectedConditions.visibilityOf(element));
}
/* Explicit wait for the Webelement on the page to be visible */
public void expliciteWaitVisiblityOfWindows(int timeToWaitInSec) {
WebDriverWait wait = new WebDriverWait(genericSteps.driver, timeToWaitInSec);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
// wait.until(ExpectedConditions.titleIs(pageTitle));
}
public void clickByElement(WebElement element) throws IOException {
explicitWait(element, 120);
if (element.isDisplayed()) {
element.click();
waitForPageToLoad(90);
}
}
public void clickByElementJavaScript(WebElement element) throws IOException {
JavascriptExecutor executor = (JavascriptExecutor)genericSteps.driver;
executor.executeScript("arguments[0].click();", element);
}
public void verifyTitle(String title) throws IOException {
genericSteps.driver.getTitle();
}
public void explicitWait1(WebElement element, int timeToWaitInSec) {
WebDriverWait wait = new WebDriverWait(genericSteps.driver, timeToWaitInSec);
wait.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.elementToBeClickable(element));
}
public void mouseOverByElement(WebElement element) throws IOException {
explicitWait(element, 1000);
new Actions(genericSteps.driver).moveToElement(element).build().perform();
}
public void mouseOverToSelectElement(WebElement element, WebElement element1) throws IOException {
explicitWait(element, 30);
Actions action = new Actions(genericSteps.driver);
action.moveToElement(element).moveToElement(element1).click().build().perform();
}
/*
* This method will switch windows using the page title
*
* @param get the title of the page
*/
public boolean switchToWindowByTitle(String title) throws Exception {
((JavascriptExecutor) genericSteps.driver).executeScript("window.focus();");
((JavascriptExecutor) genericSteps.driver).executeScript("window.focus();");
Set<String> availableWindows = genericSteps.driver.getWindowHandles();
System.out.println("HELLO");
if (!availableWindows.isEmpty()) {
for (String string : availableWindows) {
System.out.println("HELLO" + genericSteps.driver.switchTo().window(string).getTitle());
genericSteps.driver.manage().window().maximize();
waitForPageToLoad();
}
for (String windowId : availableWindows) {
String switchedWindowTitle = genericSteps.driver.switchTo().window(windowId).getTitle();
waitForPageToLoad();
if ((switchedWindowTitle.equals(title)) || (switchedWindowTitle.contains(title))) {
System.out.println(switchedWindowTitle);
return true;
}
}
Thread.sleep(3000);
waitForPageToLoad();
}
return false;
}
public void switchToWindowByTitleNew(String title) throws Exception {
((JavascriptExecutor) genericSteps.driver).executeScript("window.focus();");
((JavascriptExecutor) genericSteps.driver).executeScript("window.open();");
Set<String> availableWindows = genericSteps.driver.getWindowHandles();
System.out.println(availableWindows.toArray().length);
if (!availableWindows.isEmpty()) {
for (String string : availableWindows) {
System.out.println("HELLO" + genericSteps.driver.switchTo().window(string).getTitle());
genericSteps.driver.manage().window().maximize();
genericSteps.driver.navigate();
waitForPageToLoad();
}
for (String windowId : availableWindows) {
String switchedWindowTitle = genericSteps.driver.switchTo().window(windowId).getTitle();
waitForPageToLoad();
if ((switchedWindowTitle.equals(title)) || (switchedWindowTitle.contains(title))) {
System.out.println(switchedWindowTitle);
return;
}
}
Thread.sleep(3000);
waitForPageToLoad();
}
}
//Mahi added
public boolean switchToTabByTitleNew(String title) throws Exception {
((JavascriptExecutor) genericSteps.driver).executeScript("window.focus();");
Set<String> availableTabs = genericSteps.driver.getWindowHandles();
System.out.println(availableTabs.toArray().length);
if (!availableTabs.isEmpty()) {
for (String string : availableTabs) {
System.out.println("HELLO" + genericSteps.driver.switchTo().window(string).getTitle());
genericSteps.driver.manage().window().maximize();
genericSteps.driver.navigate();
waitForPageToLoad();
}
for (String windowId : availableTabs) {
String switchedTabTitle = genericSteps.driver.switchTo().window(windowId).getTitle();
waitForPageToLoad();
if ((switchedTabTitle.equals(title)) || (switchedTabTitle.contains(title))) {
System.out.println(switchedTabTitle);
return true;
}
}
Thread.sleep(3000);
waitForPageToLoad();
}
return false;
}
public void handleSSLError() throws Exception {
String title = genericSteps.gerDriver().getTitle();
System.out.println("The value of title is "+ title);
if(title.equalsIgnoreCase("This site isn’t secure"))
{
clickByElementJavaScript(genericSteps.gerDriver().findElement(By.id("overridelink")));
waitForPageToLoad();
}
}