1

セレン用のphpウェブドライバーを使用してIEjavascriptアラートを受け入れる必要がありますこれはFFとChromeで機能しますが、IEは失敗します

これが私が使用しているコードです:

$web_driver = new WebDriver();
// opens Internet explorer browser
$session = $web_driver->session('internet explorer');
// Navigates to page that has JS alert on close.
$session->open('http://mypage.com/');
// Closes Offer window
$session->deleteWindow();
// Accepts alert to leave page
$session->accept_alert(); // Except accept_alert isn't working correctly in IE
// Closes last window
$session->close();
// Kill session for garbage collection
unset($session);

Javaはこの答えがあり、C#にはこの答えがあることは知っていますが、Javaメソッドは同じではないため、PHP固有のソリューションを探しています

4

1 に答える 1

1

これは私が理解するのに永遠にかかりました。私が以前に行ったことは、deleteWindow()呼び出しの後で、最新のウィンドウハンドルを取得し、それにフォーカスを設定することです。アラートにフォーカスが合ったらaccept_alert()、それを呼び出すことができ、ウィンドウは期待どおりに閉じます。これがアイデアです。

$web_driver = new WebDriver();
$session = $web_driver->session('internet explorer');
$session->open('http://mypage.com/');
$session->deleteWindow();

// Here's the new part
$handles = $this->_session->window_handles(); // stores array of window handles
$new_handle = end($handles); // grabs the newest handle, in this case our alert
$this->_session->focusWindow($new_handle); // gives the alert window focus

// Should now work as expected
$session->accept_alert();
$session->close();
unset($session);

これはFirefoxおよびChromeドライバーでも機能するため、必要に応じてすべてのドライバーに同じコードを使用できます。幸運を!

于 2013-03-06T23:46:46.750 に答える