[cl-selenium-devel] Problems with cl-selenium, Drakma, and nasty JavaScript
Robin Lee Powell
rlpowell at digitalkingdom.org
Tue Jul 1 05:21:22 UTC 2008
I just moved over from Scheme, and am trying to get my project,
which is TDD-via-Selenium based, ported over. Mostly going well;
thank you for saving me the trouble of creating a Selenium port.
Again.
The problem I'm having is with a function I wrote to retrieve CSS
properties of page elements; I like to be able to check that things
are being rendered properly. As far as I know, there's nothing for
this in the Selenium API.
Here's the function. It's horrible; I apologize.
- ------------------
; Takes an element locator and a CSS property name, and returns the
; value for that property on that locator.
;
; Example:
;
; (expect-string= "And: the ephemeral bit is bolded."
; "bold"
; (element-attribute hpv "Num Ratings Text Ephemera" "font-weight"))
;
; The Javascript here is a bit scary.
(defun element-css-raw (elem prop)
(let* (
; Some browsers want font-family; some want fontFamily.
;
; *sigh*
(prop-lis (cl-ppcre:split "[-]" prop))
(camel-prop (apply #'concatenate 'string
(cons (car prop-lis) (mapcar #'(lambda (x) (string-capitalize x)) (cdr prop-lis)))))
; The actual javascript
(js
(format
nil
(concatenate 'string
"element = this.page().findElement(\"~A\"); "
"if( element.currentStyle ) "
"{ element.currentStyle.~A } "
"else { this.browserbot.getCurrentWindow()."
"getComputedStyle( element, null )."
"getPropertyValue('~A') }")
elem
camel-prop
prop))
; Running the javascript
(js-out (do-get-eval js))
; Some browers think colours look like rgb( rrr, ggg, bbb )
; (where all are decimal numbers), but we prefer #rrggbb,
; so we make it that way
(color-normalized-js-out
(cond
((cl-ppcre:scan "^\\s*rgb\\(" js-out)
(apply format nil "#~2,'0X~2,'0X~2,'0X"
(map
(lambda (num-str) (parse-integer num-str))
(cl-ppcre:split
", *"
(cl-ppcre:regex-replace
"\\)$"
(cl-ppcre:regex-replace "^\\s*rgb\\(" js-out "")
"")))))
(t js-out)))
)
;(format #t "element-css: ~A, ~A, ~A, ~A, ~A\n" elem prop camel-prop js color-normalized-js-out)
color-normalized-js-out))
- ------------------
The problem is with "element = this.page().findElement(\"~A\"); "
Specifically, the embedded ".
Drakma simply won't accept them:
Parse error:URI "http://localhost:4444/selenium-server/driver/?cmd=getEval&1=element%20%3D%20this.page().findElement(\"id%3Dhome\")%3B%20if(%20element.currentStyle%20)%20%7B%20element.currentStyle.textDecoration%20%7D%20else%20%7B%20this.browserbot.getCurrentWindow().getComputedStyle(%20element,%20null%20).getPropertyValue('text-decoration')%20%7D&sessionId=821656" contains illegal character #\" at position 100.
The obvious solution of replacing them with ' doesn't work, because
some of my xpaths have ' in them, so that fails entirely. I can't
just replace the ' in the xpaths with " to make up for *that*,
because if I do, the " still end up in the Drakma request, and again
Drakma refuses.
I haven't started hacking source for cl-selenium for Drakma yet; any
help would be appreciated.
-Robin
--
Lojban Reason #17: http://en.wikipedia.org/wiki/Buffalo_buffalo
Proud Supporter of the Singularity Institute - http://singinst.org/
http://www.digitalkingdom.org/~rlpowell/ *** http://www.lojban.org/
More information about the cl-selenium-devel
mailing list