Discussion:
[selenium-users] Trying to Open New Window Its not working
Karthick Vanithurai
2018-11-17 18:26:07 UTC
Permalink
Hi i am trying to open a new window using the below code but its not
working, please help...

package Practice;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;

public class OpenNewWindow {

public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\vanbt\\OneDrive\\Desktop\\Gecko\\chromedriver.exe");
WebDriver driver = new ChromeDriver();

//Open an browser
driver.navigate().to("https://bing.com");
Thread.sleep(3000);
//Open a new window
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "n");

}

}
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/0d44a86c-ad8b-475c-b578-8951aaffd18c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Meenal Jain
2018-11-19 13:44:15 UTC
Permalink
Hi Karthick,

You can use robot class to open a new window. Try below code.
Robot rb = new Robot();
rb.Keypress(KeyEvent.VK_CONTROL);
rb.Keypress(KeyEvent.VK_N);
rb.Keyrelease(KeyEvent.VK_N);
rb.Keyrelease(KeyEvent.VK_CONTROL);

Please let me know if you face any issue with this.

Thanks,
Meenal
Post by Karthick Vanithurai
Hi i am trying to open a new window using the below code but its not
working, please help...
package Practice;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class OpenNewWindow {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\vanbt\\OneDrive\\Desktop\\Gecko\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Open an browser
driver.navigate().to("https://bing.com");
Thread.sleep(3000);
//Open a new window
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "n");
}
}
--
You received this message because you are subscribed to the Google Groups
"Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an
To view this discussion on the web visit
https://groups.google.com/d/msgid/selenium-users/0d44a86c-ad8b-475c-b578-8951aaffd18c%40googlegroups.com
<https://groups.google.com/d/msgid/selenium-users/0d44a86c-ad8b-475c-b578-8951aaffd18c%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/CAHd%3D%3DmLPg9%3DzxA7GT6NEjLmVGApXAyObVkSsu4%3DPBh8sext8-Q%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Venu G
2018-11-21 07:02:10 UTC
Permalink
Have you tried the same with Firefox driver....

Seems Chrome is having some issue refer below
https://stackoverflow.com/questions/40843872/no-hotkeysshortcuts-works-in-chrome-using-chromedriver

On Sunday, November 18, 2018 at 10:44:47 AM UTC+5:30, Karthick Vanithurai
Post by Karthick Vanithurai
Hi i am trying to open a new window using the below code but its not
working, please help...
package Practice;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class OpenNewWindow {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver",
"C:\\Users\\vanbt\\OneDrive\\Desktop\\Gecko\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
//Open an browser
driver.navigate().to("https://bing.com");
Thread.sleep(3000);
//Open a new window
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "n");
}
}
--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-users+***@googlegroups.com.
To post to this group, send email to selenium-***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/b2859833-c36f-45ec-a2b0-225a9d240577%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...