@@ -61,6 +61,14 @@ webdriver.WebDriver.prototype.visualizerShowPoint = function() {
6161} ;
6262
6363function 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
6674WebDriverProxy . 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+
536566function 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
542573WebDriverJsController . prototype . setServerUrl = function ( serverUrl ) {
@@ -604,8 +635,12 @@ WebDriverJsController.prototype.onLogs = function(type) {
604635} ;
605636
606637WebDriverJsController . 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
619658WebDriverJsController . prototype . onSendKeys = function ( key ) {
0 commit comments