findElement(driver, path) → {Object}
findElement
Parameters:
Name | Type | Description |
---|---|---|
driver |
Object |
webdriver object of web browser. |
path |
Object |
object of path type as xpath, id, className, tagName, name properties. |
Returns:
return a object of "webElement".
- Type
- Object
Examples
Examples usage of findElement by HTML element xpath
findElement(driver, { xpath: '//*[@id="testXpath"]/div' }).then((webElement) => {
// After resolve promise We'll get the "webElement" object for HTML element whose "xpath" we pass.
}).catch((error) => {
// handle error
});
Examples usage of findElement by HTML element id
findElement(driver, { id: 'testId' }).then((webElement) => {
// After resolve promise We'll get the "webElement" object for HTML element whose "id" we pass.
}).catch((error) => {
// handle error
});
Examples usage of findElement by HTML element class
findElement(driver, { className: 'testClass' }).then((webElement) => {
// After resolve promise We'll get the "webElement" object for HTML element whose "classname" we pass.
}).catch((error) => {
// handle error
});
Examples usage of findElement by HTML element tagName
findElement(driver, { tagName: 'span' }).then((webElement) => {
// After resolve promise We'll get the "webElement" object for HTML element whose "tagname" we pass.
}).catch((error) => {
// handle error
});
Examples usage of findElement by name property of HTML element
findElement(driver, { name: 'testName' }).then((webElement) => {
// After resolve promise We'll get the "webElement" object for HTML element whose "name" property we pass.
// Similarly we can access elemets HTML by using any attribute which used in HTML element.
// As we can pass title, for, alt etc. attributes of an HTML element.
}).catch((error) => {
// handle error
});