Skip to content

Commit b1a21ea

Browse files
author
Vasyl Vavrychuk
committed
improve UI
1 parent 9acac73 commit b1a21ea

File tree

2 files changed

+51
-8
lines changed

2 files changed

+51
-8
lines changed

web/WebDriverJsDemo.html

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,29 @@
3737
<input id="getButton" type="button" value="GET" onclick="wd.onGet()"/>
3838
<input id="sourceButton" type="button" value="Source" onclick="wd.onSource()"/>
3939
<input id="screenshotButton" type="button" value="Screenshot" onclick="wd.onScreenshot()"/>
40-
<select onmouseup="wd.onLogs(this.options[this.selectedIndex].value)">
40+
<select id="logsSelect" onmouseup="wd.onLogs(this.options[this.selectedIndex].value)">
4141
<option>Logs</option>
42-
<option>browser</option>
43-
<option>driver</option>
42+
<option value="browser">browser</option>
43+
<option value="driver">driver</option>
4444
</select>
4545
</td>
4646
</tr>
4747
</table>
4848

49+
<div id="error" class="commandBlock" style="display: none; color: red;">
50+
</div>
51+
4952
<div class="commandBlock">
5053
Find element by
5154
<select name="findElementCriteria">
52-
<option>id</option>
53-
<option>name</option>
54-
<option>tag name</option>
55-
<option>xpath</option>
55+
<option value="id">id</option>
56+
<option value="name">name</option>
57+
<option value="tagName">tag name</option>
58+
<option value="xpath">xpath</option>
5659
</select>
5760
<input name="findElementKey" type="text"/>
5861
<input type="submit" value="Find element" onclick="wd.onFindElement()">
62+
<span id="foundElement" style="visibility: hidden;"></span>
5963
</div>
6064

6165
<div class="commandBlock">

web/webdriver-app.js

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ webdriver.WebDriver.prototype.visualizerShowPoint = function() {
6161
};
6262

6363
function WebDriverProxy() {
64+
for (var propertyName in webdriver.WebDriver.prototype) {
65+
if (propertyName in this)
66+
continue;
67+
68+
this[propertyName] = function() {
69+
this.handleError('WebDriver is not connected!');
70+
};
71+
}
6472
}
6573

6674
WebDriverProxy.prototype.setServerUrl = function(serverUrl) {
@@ -74,7 +82,8 @@ WebDriverProxy.prototype.setServerUrl = function(serverUrl) {
7482
var property = this.driver_[propertyName];
7583
if (typeof property === 'function') {
7684
this[propertyName] = function(impl) {
77-
return function() {
85+
return function() {
86+
self.handleError(null);
7887
return impl.apply(self.driver_, arguments);
7988
};
8089
}(property);
@@ -533,10 +542,32 @@ WebDriverJsView.prototype.updateSessionDepControls = function() {
533542
}
534543
}
535544

545+
WebDriverJsView.prototype.setFoundElementId = function(id) {
546+
var element = document.getElementById('foundElement');
547+
if (typeof id.ELEMENT === 'string') {
548+
element.innerHTML = 'Found element ' + id.ELEMENT;
549+
} else {
550+
element.innerHTML = id.ELEMENT.message;
551+
}
552+
element.style.visibility = 'visible';
553+
}
554+
555+
WebDriverJsView.prototype.setError = function(message) {
556+
var element = document.getElementById('error');
557+
if (message != null) {
558+
element.innerHTML = message;
559+
element.style.display = 'block';
560+
} else {
561+
element.innerHTML = '';
562+
element.style.display = 'none';
563+
}
564+
}
565+
536566
function WebDriverJsController() {
537567
this.driver = new WebDriverProxy();
538568
this.visualizer = new VisualizerController(this.driver);
539569
this.view = new WebDriverJsView();
570+
this.driver.handleError = this.view.setError.bind(this.view);
540571
}
541572

542573
WebDriverJsController.prototype.setServerUrl = function(serverUrl) {
@@ -604,8 +635,12 @@ WebDriverJsController.prototype.onLogs = function(type) {
604635
};
605636

606637
WebDriverJsController.prototype.onFindElement = function() {
638+
var self = this;
607639
var criteria = document.getElementsByName('findElementCriteria')[0].value;
608640
var key = document.getElementsByName('findElementKey')[0].value;
641+
642+
this.element = null;
643+
609644
if (criteria === 'id')
610645
this.element = this.driver.findElement(webdriver.By.id(key));
611646
else if (criteria === 'name')
@@ -614,6 +649,10 @@ WebDriverJsController.prototype.onFindElement = function() {
614649
this.element = this.driver.findElement(webdriver.By.tagName(key));
615650
else if (criteria === 'xpath')
616651
this.element = this.driver.findElement(webdriver.By.xpath(key));
652+
653+
this.element.toWireValue().then(function(value) {
654+
self.view.setFoundElementId(value);
655+
});
617656
};
618657

619658
WebDriverJsController.prototype.onSendKeys = function(key) {

0 commit comments

Comments
 (0)