I am using Katalon IDE for generating a script.
As my application has a signout button on top right, when I click it, IDE will generate
xpath=(.//*[normalize-space(text()) and normalize-space(.)='S'])[3]/following::span[3]
When running this in Eclipse this line gives an error. On inspecting this element I found this:
<td id="titlebar_hyperlink_8-co_0" role="presentation"
nowrap="nowrap" align="left" class=" verticalSpacer"
style="vertical-align:top;">
<span id="titlebar_hyperlink_8-lbsignout" align="left"
ctype="label" tabindex="0" targetid=
"titlebar_hyperlink_8-lbsignout" mxevent="click" accesskey="S"
class="text powerwhite anchor" style="display:block;cursor:pointer;"
title="Sign Out ALT+S" hotkey="83"><img id="titlebar_hyperlink_8-
lbsignout_image" src="btn_signout.gif" class="pwimg" border="0"
style="vertical-align:top;margin:0px;margin-left:3px;margin-right:3px;"
alt="Sign Out ALT+S"><span><span></span><span class="text hl
hlak">S</span><span>ign Out</span></span></span></td>
I'm new to selenium and all its related stuff. I would appreciate any kind of help on this. Thanks, Stack Overflow Community.
Try changing the xpath to
'.//*[@title="Sign Out ALT+S"]'
Explanation:
You want to uniquely locate an element. Usually, you would try with the id
, but the id of your element seems dynamic so it might not work in every case.
*
- this means any element, and inside of the brackets [ ]
you put the attribute you want to find the element by. I chose title because it will probably be unique on a given page.
I recommend this cheatsheet for xpath reference.