2016-11-30 1 views
0

조사한 결과 Control + t가 Chrome webdriver에서 작동하지 않는다는 것을 알았습니다. 다음은 몇 가지 내가 해봤되는 다음 작동하지 않았다selenium webdriver를 사용하여 새 크롬 탭을 여는 방법은 무엇입니까?

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

WebElement element = driver.findElement(By.linkText("Gmail")); 
    Actions actionOpenLinkInNewTab = new Actions(driver); 
    actionOpenLinkInNewTab.moveToElement(element) 
          .keyDown(Keys.COMMAND) 
          .keyDown(Keys.SHIFT) 
          .click(element) 
          .keyUp(Keys.COMMAND) 
          .keyUp(Keys.SHIFT) 
          .perform(); 

    ArrayList tabs = new ArrayList (driver.getWindowHandles()); 
    driver.switchTo().window(tabs.get(1)); 
    driver.get("http://www.yahoo.com"); 
    driver.close(); 

    driver.switchTo().window(tabs.get(0)); 
    driver.get("http://www.yahoo.com"); 

    driver.close(); 

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

당신의 수는이 문제를 해결 단계 했습니까?

사용 웨이터 :

답변

1

C#을

사용이 코드는 새 탭을 탭 사이 & 스위치를 엽니 다.

첫 페이지 순위의 탭 인덱스는 0부터 시작합니다.

var body = Waiter.Until(ExpectedConditions.PresenceOfAllElementsLocatedBy(By.TagName("body"))).FirstOrDefault(); 
body.SendKeys(Keys.Control + 't'); 
var tabs = GlobalDriver.WindowHandles; 
GlobalDriver.SwitchTo().Window(tabs[1]); 
GlobalDriver.Navigate().GoToUrl("Url"); 

코드는 C#

에 그것은 자바에서 어떻게 든 비슷합니다, 그냥 구문은 다를 수 있습니다.

희망이 도움이됩니다. (MAC OS X 경우 또는 Cmd를 +의 t)과 새로운 핸들에 대한 대기가 열 수

0

당신은 예를 들어, Ctrl +의 t을 보내 자바 로봇을 사용할 수 있습니다

// Open URL in default tab 
driver.get("https://wikipedia.org/"); 

// If Mac OS X, the key combination is CMD+t, otherwise is CONTROL+t 
int vkControl = IS_OS_MAC ? KeyEvent.VK_META : KeyEvent.VK_CONTROL; 
Robot robot = new Robot(); 
robot.keyPress(vkControl); 
robot.keyPress(KeyEvent.VK_T); 
robot.keyRelease(vkControl); 
robot.keyRelease(KeyEvent.VK_T); 

// Wait up to 5 seconds to the second tab to be opened 
WebDriverWait wait = new WebDriverWait(driver, 5); 
wait.until(ExpectedConditions.numberOfWindowsToBe(2)); 

// Switch to new tab 
List<String> windowHandles = new ArrayList<>(driver.getWindowHandles()); 
System.err.println(windowHandles); 
driver.switchTo().window(windowHandles.get(1)); 

// Open other URL in second tab 
driver.get("https://google.com/"); 

Here을 당신이 실행되고 브라우저로 Chrome을 사용하는 예입니다.

관련 문제