How to open a new tab in the same browser by using Selenium WebDriver with Java?

后端 未结 4 782
后悔当初
后悔当初 2021-01-03 16:14

I can open a new window with Selenium WebDriver by using Java and JavaScript. I am using Firefox. The code is as follows:

WebDriver driver = new FirefoxDrive         


        
相关标签:
4条回答
  • 2021-01-03 16:39

    Wasim,

    cdriver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL +"t");
    

    You can use above line to open new tab in a same browser (Works in Firefox)

    0 讨论(0)
  • 2021-01-03 16:48

    It also depends on how your browser is configured to open pop-up's.

    0 讨论(0)
  • 2021-01-03 16:50

    There is no standard support in JavaScript or HTML for opening a link in a tab vs a window. It's depending on browser and settings. Some browsers default to opening in new tabs (like Chrome and Safari). Some browser allows the user to configure the behavior. Bottom line, you shouldn't design your site to rely on opening new windows in tabs as there is no reliable and cross-browser compatible mechanism for doing that.

    0 讨论(0)
  • 2021-01-03 16:55

    It is mostly depends on your browser settings and there is no separate methods for opening link in new window or new tab

    0 讨论(0)
提交回复
热议问题