2012-01-28 34 views
2

我目前使用Selenium 2與本地Selenium Web服務器和PHP-Webdriver written by Facebook使用PHP-Webdriver在Selenium 2中切換幀

現在我想寫一個Facebook Like Button的自動化測試。因爲這個按鈕是通過iframe加載的,我首先通過$driver->frame(array('id' => 1))(我發現,Facebook加載通常是兩幀,第二幀是Like按鈕)來選擇這個幀。點擊Like按鈕後,會加載一個新的Frame,用戶也可以在其中發送評論。不幸的是,焦點仍在Like Button Frame上,所以我必須切換到第二幀。我怎樣才能做到這一點?

因爲我沒有使用Selenium RC,所以沒有Selenium.SelectFrame("relative=top")方法。我也不能使用方法driver.switchTo().defaultContent(),因爲我不使用Java webdriver。看來我只能使用JsonWireProtocol中指定的方法。如何在幀之間切換或將焦點改回到頂部幀?

回答

2

webdriver的Python的客戶端有這些方法對I幀,窗口和彈出窗口之間切換:

switch_to_active_element 
switch_to_alert 
switch_to_default_content 
switch_to_frame 
switch_to_window 

switch_to_default_content是一個你需要的。找到它的模擬php客戶端。


UPDATE: 既然你提到JasonWireProtocol:

http://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/frame

POST /會話/:的sessionId /幀

焦點轉到頁上的另一個框架。
如果幀ID爲空,服務器應切換到頁面的默認內容。

+0

方法'switch_to_default_content'沒有實現,但感謝您的文章更新^^。有用。 – 2012-02-01 22:36:58

1

我有同樣的問題。我發現的問題是,PHP webdrivers中的「框架」僅切換到當前幀以下的幀。所以,如果你想切換到當前幀以上的不同幀,那麼你是不幸的。我不得不選擇主窗口,這基本上將我重置爲頂部框架。從那裏我能夠選擇正確的框架。

//putting a sleep so the page can load 
sleep(SLEEPTIME + 5); 
//getting a list of windows on the page 
$windows = $webdriver->getWindows(); // function below 

//switching to the 
$webdriver->selectWindow($windows[0]); 

$webdriver->focusFrame('cpAppFrame'); 

public function getWindows() { 
     $request = $this->requestURL . "/window_handles"; 
     $response = $this->execute_rest_request_GET($request); 
     return $this->extractValueFromJsonResponse($response); 
    }