| <!DOCTYPE html> |
| <!-- |
| Copyright 2011 Software Freedom Conservancy. All Rights Reserved. |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
| --> |
| <title>find_element_test</title> |
| <script src="../test/test_bootstrap.js"></script> |
| <script> |
| goog.require('bot.locators'); |
| goog.require('webdriver.Builder'); |
| goog.require('webdriver.testing.asserts'); |
| goog.require('webdriver.testing.jsunit'); |
| </script> |
| <script> |
| |
| var driver; |
| |
| function setUp() { |
| driver = new webdriver.Builder().build(); |
| } |
| |
| function testCanFindElementByClassName() { |
| var el = driver.findElement(By.className('root')); |
| assertThat(el.getAttribute('id'), equals('test-dom')); |
| } |
| |
| function testCanFindElementById() { |
| var el = driver.findElement(By.id('test-dom')); |
| assertThat(el.getAttribute('className'), equals('root')); |
| } |
| |
| function testCanFindElementByXPath() { |
| var el = driver.findElement(By.xpath('//div[@class="root"]//div[2]')); |
| assertThat(el.getInnerHtml(), equals('child 2')); |
| } |
| |
| function testCanFindElementByCssSelector() { |
| assertThat(element('div.root').getAttribute('id'), |
| equals('test-dom')); |
| assertThat(element('div.root div').getInnerHtml(), equals('child 1')); |
| |
| function element(selector) { |
| return driver.findElement(By.css(selector)); |
| } |
| } |
| </script> |
| <div id="test-dom" class="root"> |
| <div id="child-1">child 1</div> |
| <div id="child-2">child 2</div> |
| </div> |