Selenium IE Driver opens link on a new window and not on new tab - selenium

I am using IE11 for my selenium tests. I Am clicking on a link which when done manually opens up the link on a new tab.
When I am trying to do the same thing with Selenium, it does not open the link on a new tab rather, it opens up on a new window.
Is there a way to force IE to click and open the link on a new tab?
I am able to achieve the same with Firefox and Chrome, but with IE, as soon as the link is clicked, it opens on a new window rather than a new tab.
if (BROWSER_TYPE.equals("IE")) {
Utility.log(this.getClass().getName(),Level.INFO,"Browser type is IE downloading firefox driver is required.");
WebDriverManager webDriverManagerObject = WebDriverManager.iedriver();
webDriverManagerObject.targetPath(DRIVER_DOWNLOAD_PATH);
if(!DRIVER_VERSION.equals("latest")) {
WebDriverManagerObject = webDriverManagerObject.version(DRIVER_VERSION);
}
Utility.log(this.getClass().getName(),Level.DEBUG,"Launching IE Browser");
webDriverManagerObject.setup();
driver = new InternetExplorerDriver();
}
Expected Result: Clicking on the Link should open the page on a new tab on the same window in IE
Actual result: Clicking on the Link opens the page on a new window rather than a new tab.

Related

protractor not able to open new tab window which contains pdf tab

While testing one angular website there is button, When i am clicking on it - It should open new tab which contains pdf.
What i tried - Manual Execution working properly
1) I used JAVA script Executor but it's not working.
browser.executeScript("document.querySelector('My Query Selector').click();");
2) simple click also not opening new tab in chrome protractor testing
const elm = element(by.xpath("//button[#class='My Class Name']"));
elm.click();
chrome Version = Version 74.0.3729.169 (Official Build) (64-bit)
browser.addMockModule('Infrastructure.SignalR', () => {
angular.module('Infrastructure.SignalR', []);
});
does this browser.addMockModule affects to not opening new tab ?
Try using Control+Click to check whether it is working.
const elm = element(by.xpath("//button[#class='My Class Name']"));
Actions action=new Actions(driver);
action.keyDown(Keys.CONTROL).click(elm).keyUp(Keys.CONTROL).build().perform();

Why with FirefoxProfile script window.open() open new window instead tab?

I had a very strange issue: for the open new tab(not a window) in Firefox thougth Selenium I use:
((JavascriptExecutor) driver).executeScript("window.open()");
And this worked ok, but when I added FirefoxProfile for FirefoxOptions like this:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("media.peerconnection.enabled", false);
options.setProfile(profile);
And instead of new Tab in the same window .executeScript("window.open()"); open all in new window. But I need both things new tab for window.open() script and set media.peerconnection.enabled to false.
How can this happen why JS behavior depending on the profile?
How can I fix this?
I mean set media.peerconnection.enabled without a profile or prevent change JS behavior with Profile.

When I click on link under menu which is inside the iframe, it opens the new browser window

In below code of selenium script to access iframe elements.
I open a menu in first webElement and and then in second webElement I click on link watches under menu.
It redirects the page properly but it opens same page in new browser window also.
i.e. 2 browser are opened. How to prevent new browser to be opened.
driver.switchTo().frame(driver.findElement(By.id("watches_iframe")));
Thread.sleep(3000);
WebElement menu = driver.findElement(By.xpath("//div[#id='pm-
nav']//div[#class='pm-menu-button']"));
menu.click();
// when I click on below link it redirects the page properly but opens same
// page in new window also
WebElement store = driver.findElement(By.xpath("//div[#id='pm-menu-
master']//li[#class='item-store']//a//span[1]"));
store.click();

Selenium : New tab is not getting opened on same browser in Chrome

I'm trying to open a new tab in same browser but it doesn't seem to work. I'm using Chrome Version 58.0.3029.110 (64-bit) and Selenium 3.0.0.
I used the below code:
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "\t");
try using JavascriptExecutor as below:
((JavascriptExecutor) driver).executeScript("window.open('https://www.google.com');");
You can also use Robot class with Selenium Webdriver to open a new tab. We need to follow the below three steps-
Simulate pressing of Ctrl+t keys of keyboard using Robot class.
Switch to the new tab in selenium using driver.switchTo() command.
Open the desired link on new tab.
Code snippet-
//Launch the first URL
driver.get("http://www.google.com");
//Use robot class to press Ctrl+t keys
Robot robot = new Robot();
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_T);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_T);
//Switch focus to new tab
ArrayList<String> tabs = new ArrayList<String (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
//Launch URL in the new tab
driver.get("http://google.com");
Source: Code snippet from Open a new tab in Selenium - ArtOfTesting

Selenium throwing exception when a modal dialog is shown at start of ie instance

I have to automate a scenario where a modal dialog opens immediately after ie is open i.e.
from selenium import webdriver
driver=webdriver.Ie()
Once i do this, IE instance opens and an IE modal dialog opens on top of ie.
Now selenium closes this modal dialog immediately and throws an exception:
Unexpected alert present, Modal Dialog present.
But i have to handle this modal dialog.
Is there any way to handle this dialog and make sure selenium does not throw exception and quit?
Had the same problem, selenium dismissing the alert (as if Cancel was clicked), where you want to confirm (as if OK was clicked).
For me it worked to initialize the driver by initializing webdriver with the UnexpectedAlertBehavior option, as per below
private static InternetExplorerOptions internetExplorerOptions = new InternetExplorerOptions{ UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Accept };
public static InternetExplorerDriver Driver = new InternetExplorerDriver(SeleniumLocator.GetSeleniumDriverPath(), internetExplorerOptions);