Selenium chrome opens the link on the new tab, seleniumchrome

Source: Internet
Author: User

Selenium chrome opens the link on the new tab, seleniumchrome

Currently, chrome is the most stable browser for implementing webdriver. How can I use webdriver to open multiple tabs and links? What I can find everywhere is usually how to open tabs.
It is easy to open a tab. The shortcut key for chrome to open a tab is ctrl + t. You can just input the ctrl + t button event. There are many implementation methods:
1:
Actions actionOpenLinkInNewTab = new Actions (driver );
ActionOpenLinkInNewTab. keyDown (Keys. CONTROL). sendKeys ("t"). keyUp (Keys. CONTROL). perform ();

2:
Driver.findElement(By.css Selector ("body"). sendKeys (Keys. CONTROL + "t ");

Open all the code of the new link on the new tab (Google ):
String baseUrl = "http://www.google.co.uk /";
Driver. get (baseUrl );
Driver.findElement(By.css Selector ("body"). sendKeys (Keys. CONTROL + "t ");

ArrayList <String> tabs = new ArrayList <String> (driver. getWindowHandles ());
Driver. switchTo (). window (tabs. get (1); // switches to new tab
Driver. get ("https://www.facebook.com ");

Driver. switchTo (). window (tabs. get (0); // switch back to main screen
Driver. get ("https://www.news.google.com ");

 

Url: http://equalxx.iteye.com/blog/2291520

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.