2016-02-14 128 views

回答

0

像這樣的東西應該工作:

$driver = RemoteWebDriver::create($host, DesiredCapabilities::chrome()); 
$driver->get('http://mine.com'); 

// Via driver: http://facebook.github.io/php-webdriver/classes/RemoteWebDriver.html#property_keyboard 

$kbd = $driver->getKeyboard(); 
$kbd->sendKeys(WebDriverKeys.CONTROL,'t'); 

// Via an element: http://facebook.github.io/php-webdriver/classes/WebDriverElement.html#method_sendKeys 

$element = $driver->findElement(WebDriverBy::id('somethingOnScreen')); 
$element->sendKeys(WebDriverKeys.CONTROL,'t'); 
+0

感謝您的回答,但沒有它沒有工作。仍然打開一個新窗口,而不是一個新標籤。我有這些: '$ host ='http:// localhost:4444/wd/hub'; $ driver = RemoteWebDriver :: create($ host,DesiredCapabilities :: chrome()); $ driver-> get($ url); $ kbd = $ driver-> getKeyboard(); $ kbd-> sendKeys(WebDriverKeys.CONTROL,'t'); $ uname = $ driver-> findElement( WebDriverBy :: xpath('/ html/body/div [5]/div/div [1]/div [2]/div/form/input [1]') );' –

+0

只是澄清:'get'調用創建一個窗口,Ctrl-T創建另一個窗口(即它肯定會做什麼)? –

+0

我需要檢查你所看到的,因爲通常認爲Ctrl-T(或Cmd-T for Mac)會 - 如果它工作的話 - 打開一個新標籤頁,請參閱:http://stackoverflow.com/ a/19441842/954442 –

相關問題