How to open a link in new tab (chrome) using Selenium WebDriver?

后端 未结 14 2483
余生分开走
余生分开走 2020-11-30 03:37
System.setProperty(\"webdriver.chrome.driver\", \"D:\\\\softwares\\\\chromedriver_win32\\\\chromedriver.exe\");

WebDriver driver = new ChromeDriver();
driver.manage         


        
14条回答
  •  眼角桃花
    2020-11-30 04:08

    First open empty new Tab by using the keys Ctrl + t and then use .get() to fetch the URL you want. Your code should look something like this -

    String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
    driver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
    
    driver.get("www.facebook.com");
    

    If you want to open a link on the current view in a new tab then the code you've written above can be used. Instead of By.linkText() make sure you use the appropriate By selector class to select the web element.

提交回复
热议问题