Core idea: Use the keyboard shortcuts in Firefox or other browsers and then work with the action.
Firefox shortcut key: https://support.mozilla.org/en-US/kb/keyboard-shortcuts-perform-firefox-tasks-quickly
The following is a code example:
package webdriver;import java.util.logging.logger;import org.openqa.selenium.keys;import org.openqa.selenium.webdriver;import org.openqa.selenium.firefox.firefoxdriver;import org.openqa.selenium.interactions.actions;import org.testng.annotations.afterclass;import org.testng.annotations.beforeclass;import org.testng.annotations.test;public class Testwebdriver {private static final logger logger = logger.getlogger ( TestWebDriver.class.getName ());p rivate webdriver webdriver; @BeforeClasspublic void Beforeclass () {webdriver = new firefoxdriver ();} @Testpublic void f () {webdriver.get ("http://www.sohu.com"); String title = webdriver.gettitle (); Actions actions = new actions (Webdriver);//open a new tabactions.keydown ( Keys.control). SendKeys ("T"). KeyUp (Keys.control). Perform ();//change to the second wIndowwhile (True) {Actions.keydown (Keys.control). SendKeys (Keys.tab). KeyUp (Keys.control). Perform (); Logger.info ( Webdriver.gettitle ()); if (!title.equals (Webdriver.gettitle ())) {Break;}}} @AfterClasspublic void afterclass () {webdriver.quit ();}}
Webdriver Action Tab