本文介绍了如何使用硒webdriver在新标签页(chrome)中打开链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
System.setProperty("webdriver.chrome.driver", "D:\\softwares\\chromedriver_win32\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("https://mail.google.com/");
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("www.facebook.com")).sendKeys(selectLinkOpeninNewTab);
新标签正在打开,但url链接未打开
new tab is opening but url link is not opening
推荐答案
我检查下面的代码,它对我来说工作得很好。我从找到答案。
I checked with below code and it works fine for me. I found answer from here.
driver = new ChromeDriver();
driver.manage().window().maximize();
baseUrl = "http://www.google.co.uk/";
driver.get(baseUrl);
driver.findElement(By.cssSelector("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");
这篇关于如何使用硒webdriver在新标签页(chrome)中打开链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!