Closed alindsay55661 closed 11 years ago
This looks normal. I think you should just be able to check the error status. alternatively you may use elementByXXXOrNull or elementByXXXIfExists, which avoids the exception, using the elements method on the server instead of elements.
Great thanks.
@alindsay55661 A hack I used for displaying better error message. It is in coffeescript
{browser} = wdSync.remote()
# Hack to display better error message
# And display the line actually caused the error
for k of browser
do (k) ->
fn = browser[k]
browser[k] = ->
args = Array.prototype.slice.call arguments, 0
try
return fn.apply browser, args
catch e
message = e.cause?.value.message ? e['jsonwire-error']?.detail ? e
message += "\n Function: #{k}, Args: #{JSON.stringify args}"
throw new Error message
How to check an element exists before trying to use it example.
var element=false; element=browser.elementByXPathIfExists(bogusSelector); if (element){title=element.text();}
For example, when I execute:
Sauce Labs correctly reports: "The element could not be found". Also wd-sync fails with:
How can I trap this? I can't figure it out.