0

When i click on copy link it means url is copied , then open new tab and paste the copied url in new tab using selenium webdriver. Below code is working in windows not in mac. when i used this code in mac system, some java software icon is coming in taskbar. Attached screenshot for your reference.Java software icon in right corner and application screenshotError in console

My Code:

 String element=Util.OR_VF_MY_ACCOUNT_PAGE.getProperty("myAccountPageCopyUrlLinkInWishList");
            $(element).click();

    winHandleBefore= getDriver().getWindowHandle();
            Set<String> handles =  getDriver().getWindowHandles();
            //getDriver().findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_T);
            robot.keyRelease(KeyEvent.VK_T);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            for(String windowHandle  : handles)
            {
                if(!windowHandle.equals(winHandleBefore))
                {
                    getDriver().switchTo().window(windowHandle);
                }
            }
            Util.pause(4);
            robot.keyPress(KeyEvent.VK_CONTROL);
            robot.keyPress(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_V);
            robot.keyRelease(KeyEvent.VK_CONTROL);
            Util.pause(4);
            robot.keyPress(KeyEvent.VK_ENTER);
            robot.keyRelease(KeyEvent.VK_ENTER);
            Util.pause(4);
ksyam
  • 1
  • Not control, by mistake i have added. In mac we have to use command.Please resolve this issue – ksyam Dec 23 '16 at 09:55
  • Does this mean this is not the correct code? If so please [edit](http://stackoverflow.com/posts/41298918/edit) your question to prevent confusion. – n247s Dec 23 '16 at 09:59
  • java control panel icon is coming. can anyone help on this. – ksyam Dec 27 '16 at 08:11

1 Answers1

0

I think its because on a Mac/Unix OS there is no "Control" key. Try to use the "Command" key instead on Mac/unix systems.

Here is a post on how to check which system is operating so you can change from "Ctrl" to "Command" automatically

Edit

With javascript you are able to open new tabs/windows depending on the browser implementation. I have no idea if a new window will be accesible through the same WebDriver instance (and I can't test it out atm). But basically this snippit should work on most Drivers.

// driver is your WebDriver instance
if (driver instanceof JavascriptExecutor) {
    ((JavascriptExecutor)driver).executeScript(
    "var win = window.open('http://www.example.com/', '_blank');" +
    "if (win) {" +
    "    //Browser has allowed it to be opened" +
    "    win.focus();" +
    "} else {" +
    "    //Browser has blocked it" +
    "    alert('new tab/window couldn't be opened');" +
    "}");
} else {
    throw new IllegalStateException("This driver does not support JavaScript!");
}
n247s
  • 1,898
  • 1
  • 12
  • 30
  • Thanks for your comments. I have added command key on mac. But issue is i need to open new tab without clicking any link, just i have to copy the url and paste in new tab using code on mac.For that i was using Robot code but when i run this code,some java software icon was coming on task bar. – ksyam Dec 26 '16 at 07:15
  • Can anyone give rply for this question as i am waiting for this. Please tell me – ksyam Dec 27 '16 at 04:42
  • @ksyam Unfortunatly there is no official way to open new tabs in selenium. Most try to send the ('ctrl'/'command') + 't' to the 'body' element of the page (or just like you with a robot). With both ways it is not 100% fail proof. One way to open new tabs/window (depending on the browser type) is using javascript. Ill edit my answer with an example script you can run in your browser. – n247s Dec 27 '16 at 09:52