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

Commit bc15d4c

Browse files
committed
Merge pull request #37 from beckyconning/ready/attr-type-fix
Fixed attribute type bug
2 parents 00ef7af + 29c6d6b commit bc15d4c

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

src/Selenium.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,20 @@ exports.getCssValue = function(el) {
180180
};
181181
};
182182

183-
exports.getAttribute = function(el) {
184-
return function(str) {
185-
return function(cb, eb) {
186-
return el.getAttribute(str).then(cb).thenCatch(eb);
183+
exports._getAttribute = function(nothing) {
184+
return function(just) {
185+
return function(el) {
186+
return function(str) {
187+
return function(cb, eb) {
188+
return el.getAttribute(str).then(function(attr) {
189+
if (attr === null) {
190+
cb(nothing);
191+
} else {
192+
cb(just(attr));
193+
}
194+
}).thenCatch(eb);
195+
};
196+
};
187197
};
188198
};
189199
};

src/Selenium.purs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,14 @@ foreign import executeStr :: forall e. Driver -> String -> Aff (selenium :: SELE
145145
foreign import sendKeysEl :: forall e. String -> Element -> Aff (selenium :: SELENIUM|e) Unit
146146
foreign import clickEl :: forall e. Element -> Aff (selenium :: SELENIUM|e) Unit
147147
foreign import getCssValue :: forall e. Element -> String -> Aff (selenium :: SELENIUM|e) String
148-
foreign import getAttribute :: forall e. Element -> String -> Aff (selenium :: SELENIUM|e) String
148+
foreign import _getAttribute :: forall e a. Maybe a -> (a -> Maybe a) ->
149+
Element -> String -> Aff (selenium :: SELENIUM|e) (Maybe String)
150+
151+
-- | Tries to find an element starting from `document` will return `Nothing` if there
152+
-- | is no element can be found by locator
153+
getAttribute :: forall e. Element -> String -> Aff (selenium :: SELENIUM|e) (Maybe String)
154+
getAttribute = _getAttribute Nothing Just
155+
149156
foreign import getText :: forall e. Element -> Aff (selenium :: SELENIUM|e) String
150157
foreign import isDisplayed :: forall e. Element -> Aff (selenium :: SELENIUM|e) Boolean
151158
foreign import isEnabled :: forall e. Element -> Aff (selenium :: SELENIUM|e) Boolean

src/Selenium/Monad.purs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ isEnabled = lift <<< S.isEnabled
152152
getCssValue :: forall e o. Element -> String -> Selenium e o String
153153
getCssValue el key = lift $ S.getCssValue el key
154154

155-
getAttribute :: forall e o. Element -> String -> Selenium e o String
155+
getAttribute :: forall e o. Element -> String -> Selenium e o (Maybe String)
156156
getAttribute el attr = lift $ S.getAttribute el attr
157157

158158
getText :: forall e o. Element -> Selenium e o String

0 commit comments

Comments
 (0)