Skip to content

Commit bfe1a28

Browse files
author
Vasyl Vavrychuk
committed
WebDriverJs app: nicer work with active window
1 parent 6a22d09 commit bfe1a28

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

web/webdriver-app.js

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -682,24 +682,34 @@ WebDriverJsController.prototype.onClick = function() {
682682
};
683683

684684
WebDriverJsController.prototype.onListWindowHandles = function() {
685+
var self = this;
685686
var select = document.getElementById('windowList');
686-
this.driver.getAllWindowHandles().then(function(handles) {
687-
select.innerHTML = '';
688-
for (var handleIndex in handles) {
689-
var handle = handles[handleIndex];
690-
var item = document.createElement('option');
691-
item.setAttribute('value', handle);
692-
item.innerHTML = handle;
693-
select.appendChild(item)
694-
}
695-
document.getElementById('windowList').style.visibility = 'visible';
696-
document.getElementById('chooseWindow').style.visibility = 'visible';
687+
this.driver.getWindowHandle().then(function(activeWindowHandle) {
688+
self.driver.getAllWindowHandles().then(function(handles) {
689+
select.innerHTML = '';
690+
for (var handleIndex in handles) {
691+
var handle = handles[handleIndex];
692+
var item = document.createElement('option');
693+
item.setAttribute('value', handle);
694+
item.innerHTML = handle;
695+
if (activeWindowHandle == handle) {
696+
item.innerHTML += ' (active)';
697+
item.selected = true;
698+
}
699+
select.appendChild(item)
700+
}
701+
document.getElementById('windowList').style.visibility = 'visible';
702+
document.getElementById('chooseWindow').style.visibility = 'visible';
703+
});
697704
});
698705
};
699706

700707
WebDriverJsController.prototype.onChooseWindow = function() {
708+
var self = this;
701709
var handle = document.getElementById('windowList').value;
702-
this.driver.switchTo().window(handle);
710+
this.driver.switchTo().window(handle).then(function() {
711+
self.onListWindowHandles();
712+
});
703713
};
704714

705715
WebDriverJsController.prototype.onSetWindowSize = function() {

0 commit comments

Comments
 (0)