Skip to content

Commit

Permalink
added element post/get commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasyl Vavrychuk committed Dec 18, 2013
1 parent bfe1a28 commit d369690
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 17 deletions.
58 changes: 47 additions & 11 deletions web/WebDriverJsDemo.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style type="text/css">
.unitLabel {
font-size: small;
Expand All @@ -15,6 +16,10 @@
#keyboard input {
min-width: 30px;
}

#findElementPanel td {
vertical-align: top;
}
</style>
<script src="webdriver.js"></script>
<script src="base64-arraybuffer.js"></script>
Expand Down Expand Up @@ -49,17 +54,48 @@
<div id="error" class="commandBlock" style="display: none; color: red;">
</div>

<div class="commandBlock">
Find element by
<select name="findElementCriteria">
<option value="id">id</option>
<option value="name">name</option>
<option value="tagName">tag name</option>
<option value="xpath">xpath</option>
</select>
<input name="findElementKey" type="text"/>
<input type="submit" value="Find element" onclick="wd.onFindElement()">
<span id="foundElement" style="visibility: hidden;"></span>
<div id="findElementPanel" class="commandBlock">
<table>
<tr>
<td>
Find element by
</td>
<td>
<select name="findElementCriteria">
<option value="id">id</option>
<option value="name">name</option>
<option value="tagName">tag name</option>
<option value="xpath">xpath</option>
</select>
</td>
<td>
<input name="findElementKey" type="text"/>
</td>
<td>
<input type="submit" value="Find element" onclick="wd.onFindElement()"/>
</td>
<td>
<span id="foundElement" style="visibility: hidden;"></span>
</td>
<td>
<span id="elementActions" style="visibility: hidden;">
<input type="submit" value="Click" onclick="wd.onElementClick()"/>
<input type="submit" value="Submit" onclick="wd.onElementSubmit()"/>
<input type="submit" value="Clear" onclick="wd.onElementClear()"/>

<input type="submit" value="Tag name" onclick="wd.onElementTagName()"/>
<input type="submit" value="Text" onclick="wd.onElementText()"/>

<input type="submit" value="Location" onclick="wd.onElementLocation()"/>
<input type="submit" value="Size" onclick="wd.onElementSize()"/>

<input type="submit" value="Selected?" onclick="wd.onElementIsSelected()"/>
<input type="submit" value="Enabled?" onclick="wd.onElementIsEnabled()"/>
<input type="submit" value="Displayed?" onclick="wd.onElementIsDisplayed()"/>
</span>
</td>
</tr>
</table>
</div>

<div class="commandBlock">
Expand Down
65 changes: 59 additions & 6 deletions web/webdriver-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,10 +555,13 @@ WebDriverJsView.prototype.setFoundElementId = function(id) {
var element = document.getElementById('foundElement');
if (typeof id.ELEMENT === 'string') {
element.innerHTML = 'Found element ' + id.ELEMENT;
element.style.visibility = 'visible';
document.getElementById('elementActions').style.visibility = 'visible';
} else {
element.innerHTML = id.ELEMENT.message;
element.style.visibility = 'hidden';
this.setError(id.ELEMENT.message);
document.getElementById('elementActions').style.visibility = 'hidden';
}
element.style.visibility = 'visible';
}

WebDriverJsView.prototype.setError = function(message) {
Expand Down Expand Up @@ -669,6 +672,60 @@ WebDriverJsController.prototype.onFindElement = function() {
});
};

WebDriverJsController.prototype.onElementClick = function() {
this.element.click();
};

WebDriverJsController.prototype.onElementSubmit = function() {
this.element.submit();
};

WebDriverJsController.prototype.onElementClear = function() {
this.element.clear();
};

WebDriverJsController.prototype.onElementTagName = function() {
this.element.getTagName().then(function(value) {
alert('Element tag name: ' + value);
});
};

WebDriverJsController.prototype.onElementText = function() {
this.element.getText().then(function(value) {
alert('Element text: ' + value);
});
};

WebDriverJsController.prototype.onElementLocation = function() {
this.element.getLocation().then(function(value) {
alert('Element location: ' + JSON.stringify(value));
});
};

WebDriverJsController.prototype.onElementSize = function() {
this.element.getSize().then(function(value) {
alert('Element size: ' + JSON.stringify(value));
});
};

WebDriverJsController.prototype.onElementIsSelected = function() {
this.element.isSelected().then(function(value) {
alert('Element selection: ' + value);
});
};

WebDriverJsController.prototype.onElementIsEnabled = function() {
this.element.isEnabled().then(function(value) {
alert('Element enabled: ' + value);
});
};

WebDriverJsController.prototype.onElementIsDisplayed = function() {
this.element.isDisplayed().then(function(value) {
alert('Element displayed: ' + value);
});
};

WebDriverJsController.prototype.onSendKeys = function(key) {
if (this.element) {
this.element.sendKeys(key);
Expand All @@ -677,10 +734,6 @@ WebDriverJsController.prototype.onSendKeys = function(key) {
}
};

WebDriverJsController.prototype.onClick = function() {
this.element.click();
};

WebDriverJsController.prototype.onListWindowHandles = function() {
var self = this;
var select = document.getElementById('windowList');
Expand Down

0 comments on commit d369690

Please sign in to comment.