In SeleniumIDE, I am attempting to call javascript.
This seems like a common scenario for others as well.
My test suite begins with a login step.
I want the suite to start by ensuring that I am logged out and logging me out if I am not already logged out. I can determine my log-in status by checking for the presence of a 'Logout' hyperlink.
However, I only want to click on the logout link if I am currently logged in; otherwise, I want to do nothing to prevent errors raised by clicking on a non-existent element when I am not logged in.
So logically, this translates to:
if the logout link UI element exists,
click on the logout link
else
do nothing
end
Since basic SeleniumIDE doesn't support if-then
statements, I was hoping to achieve this in JavaScript itself.
Something along the lines of:
store javascript{if ([a with text 'Logout' exists]) then click on it end;} id1
Alternatively, visiting the URL directly could be an option (e.g., http://my-apps-domain/users/sign_out), but I'm unsure of the exact syntax.
The relevant HTML code is:
<li><a href="/users/sign_out">Logout</a></li>
If the logout link exists, I would prefer to click on the anchor tag (or visit the URL directly); otherwise, take no action.
If possible, I would like to avoid using jQuery.
Update: Even using
javascript{window.location.replace('http://google.com')}
closes my SeleniumIDE window and opens Google in a new window without affecting the actual window where the tests are running.