本文介紹了在 Selenium WebDriver 中打開一個新選項卡后,如何使其成為瀏覽器中的可見/活動選項卡?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用以下 WebDriver Java 代碼打開一個新選項卡(當然可能有更好的方法來做到這一點):
I am using the following WebDriver Java code to open a new tab (granted there are possibly better ways to do this) :
WebElement link = driver.findElement(By.id("home_button"));
Actions newTab = new Actions(driver);
newTab.keyDown(Keys.CONTROL).click(link).keyUp(Keys.CONTROL).build().perform();
ArrayList<String> openTabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(openTabs.get(1));
driver.navigate().to("http://google.com");
而且效果很好,我所做的任何進一步操作都會應用于該新標簽,但它在我的屏幕上不可見,我仍然可以看到打開的第一個標簽.有什么方法可以更改在我的窗口中可見的選項卡嗎?
And it works perfectly well, and any further actions I do are applied to that new tab, but it is not visible on my screen, I can still see the first tab that was opened. Is there any way to change which tab is visible in my window?
謝謝
推薦答案
切換標簽,使用
newTab.sendKeys(Keys.chord(Keys.CONTROL,Keys.TAB)).perform();
這篇關于在 Selenium WebDriver 中打開一個新選項卡后,如何使其成為瀏覽器中的可見/活動選項卡?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!