Skip to content
This repository was archived by the owner on Jan 17, 2020. It is now read-only.

Commit 5096e84

Browse files
committed
Merge pull request #23 from beckyconning/ready/refactored-finds
Refactored _exact and _find
2 parents a2f55ef + 9d4eada commit 5096e84

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

src/Selenium.js

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,11 @@ function _find(nothing) {
111111
return function(driver) {
112112
return function(by) {
113113
return function(cb) {
114-
driver.isElementPresent(by)
115-
.then(function(is) {
116-
if (is) {
117-
var el = driver.findElement(by);
118-
return cb(just(el));
119-
} else {
120-
return cb(nothing);
121-
}
122-
})
123-
.thenCatch(function() {
124-
return cb(nothing);
125-
});
126-
114+
driver.findElement(by).then(function(el) {
115+
return cb(just(el));
116+
}).thenCatch(function() {
117+
return cb(nothing);
118+
});
127119
};
128120
};
129121
};
@@ -133,20 +125,7 @@ function _find(nothing) {
133125
function _exact(driver) {
134126
return function(by) {
135127
return function(cb, eb) {
136-
driver.isElementPresent(by)
137-
.then(function(is) {
138-
if (is) {
139-
var el = driver.findElement(by);
140-
return cb(el);
141-
} else {
142-
var error = "couldn't find element using locator " + by.toString();
143-
return eb(new Error(error));
144-
}
145-
})
146-
.thenCatch(function(e) {
147-
return eb(e);
148-
});
149-
128+
driver.findElement(by).then(cb).thenCatch(eb);
150129
};
151130
};
152131
}

0 commit comments

Comments
 (0)