2

When I open new tab on IE, I can't handle this. How to handle new IE tab and navigate to the url?

I use Ctrl+T

  • Hi @MosheSlavin Thanks for your helps. But I need to handle New IE tab browser to find elements. Ít's work with Chrome, But IE isn't. – Trung Nghĩa Cao Jun 05 '19 at 08:54
  • 1
    You should explain more in your question... what have you tried? – Moshe Slavin Jun 05 '19 at 08:55
  • My script WebUI.openBrowser('google.com') WebDriver driverInstance = DriverFactory.getWebDriver() //driverInstance.findElements(By.cssSelector('input[name="btnK"]')).get(0).sendKeys(KeyEvent.VK_CONTROL,KeyEvent.VK_T) WebUI.sendKeys(null, Keys.chord(Keys.CONTROL,"t")) driverInstance.switchTo().defaultContent() driverInstance.get("google.com") It's not work with IE browser. – Trung Nghĩa Cao Jun 05 '19 at 09:28
  • Looks like you are opening a new tab here. IE will block this by default. (It decides that this is a popup and will prompt the user to accept...) – pcalkins Jun 05 '19 at 17:12

3 Answers3

2

You can use:

driver.switchTo().window()

Using JavaScriptExecutor is generally not recommended.

You should have a look at this question and try Turning on Compatibility Mode.

Also, have a look at this answer for general info on using Selenium with IE.

Hope this helps!

Moshe Slavin
  • 4,696
  • 5
  • 18
  • 34
0

Try with JavaScript executor,

JavascriptExecutor js = (JavascriptExecutor) driverInstance;
js.executeScript("window.open(arguments[0], 'blank')", null):
Moshe Slavin
  • 4,696
  • 5
  • 18
  • 34
Magesh
  • 168
  • 1
  • 2
  • 16
0

Try to refer line of code may help to switch tabs.

//Switching between tabs using CTRL + tab keys.
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"\t");
//Switch to current selected tab's content.
driver.switchTo().defaultContent();

for more information you can refer links below.

(1) How To Open Tab And Switching Between Tabs In Selenium WebDriver

(2) Selenium 101: Managing Multiple Tabs

Deepak-MSFT
  • 8,111
  • 1
  • 6
  • 14
  • WebUI.openBrowser('google.com') WebDriver driverInstance = DriverFactory.getWebDriver() //driverInstance.findElements(By.cssSelector('input[name="btnK"]')).get(0).sendKeys(KeyEvent.VK_CONTROL,KeyEvent.VK_T) WebUI.sendKeys(null, Keys.chord(Keys.CONTROL,"t")) driverInstance.switchTo().defaultContent() driverInstance.get("google.com") – Trung Nghĩa Cao Jun 05 '19 at 09:25
  • First I suggest you to make a test using new sample code and just try to switch the tabs from it. Once it work than try to implement in your original code. I also noticed that your code is not using '\t'. It is missing '\'. – Deepak-MSFT Jun 05 '19 at 09:54