Xpath not working sometimes

2,330 views
Skip to first unread message

mukesh rawat

unread,
May 3, 2012, 5:31:47 AM5/3/12
to webdriver
HI,

In my application unique identifier taken is xpath.
i.e. xpath=//img[contains(@src,'https://staticprogressive-
dev.mymitchell.com/static/images/menuButton_icon-workqueue.gif')]"

xpath=/html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/td/span/
table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/
tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a



Sometime they works fine and sometimes throws error:

org.openqa.selenium.NoSuchElementException: Unable to find element
with xpath == /html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/
td/span/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/
tbody/tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a (WARNING:
The server did not provide any stacktrace information)
Command duration or timeout: 391 milliseconds


Thanks,
Mukesh
mraw...@gmail.com

darrell

unread,
May 3, 2012, 8:25:07 AM5/3/12
to webdriver
There isn't really enough information here to help you. You show no
evidence of trying to figure it out yourself. Do you notice any
pattern? Does it work with one browser but not another? Which browser
are you using? Does it fail more on one browser than another? An HTML
snippet might help. Is the application under test using AJAX or
modifying the DOM via Javascript?

Darrell
> mrawat...@gmail.com

mukesh rawat

unread,
May 3, 2012, 9:01:37 AM5/3/12
to webdriver
My application only opens in IE.
Both xpath works fine sometime but many times they doesn't work.

Amit

unread,
May 3, 2012, 5:53:32 AM5/3/12
to webdriver
Create a Array List of all Img tag using findElement(by.tagName("img")
commond & then Click on the desired index element of the created list.
> mrawat...@gmail.com

NareshKumar

unread,
May 3, 2012, 6:18:47 AM5/3/12
to webd...@googlegroups.com
if am correct, it would be browser dependent, check for drivers.


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.




--
Have a Nice Day
Thanks n Regards
Naresh

Mike Riley

unread,
May 3, 2012, 12:01:18 PM5/3/12
to webd...@googlegroups.com
Please show your code where you are using the XPath locators.

Any time some says "they sometimes work and sometimes don't" makes me believe you are not waiting for them to show up, so that sometimes they show up quickly enough and sometimes the browser doesn't render them in time.  A timeout of 391ms is very short.

Another thing is that your second XPath is an absolute path that would be very fragile.  One minor change to that web page would break it.  The first one is much more robust, because it could only break if a different image path was used.  I would seriously look at improving that second XPath to be just "//a[<something>]" so it is not so fragile.

Mike

Chakri

unread,
May 3, 2012, 11:51:35 PM5/3/12
to webdriver
Good suggestion Mike,

we have been using the relative XPATH concept from the beginning of
Automation and it really helped us a lot.
simple to write. use tools like Xpather (on Firefox) & FirePath (Add-
on to Firebug (add-on to Firefox)) to evaluate your relative Xpaths.

Chakri

On May 3, 9:01 pm, Mike Riley <lvskip...@cox.net> wrote:
> Please show your code where you are using the XPath locators.
>
> Any time some says "they sometimes work and sometimes don't" makes me
> believe you are not waiting for them to show up, so that sometimes they
> show up quickly enough and sometimes the browser doesn't render them in
> time.  A timeout of 391ms is very short.
>
> Another thing is that your second XPath is an absolute path that would be
> very fragile.  One minor change to that web page would break it.  The first
> one is much more robust, because it could only break if a different image
> path was used.  I would seriously look at improving that second XPath to be
> just "//a[<something>]" so it is not so fragile.
>
> Mike
>
> On Thursday, May 3, 2012 2:31:47 AM UTC-7, mukesh rawat wrote:
>
> > HI,
>
> > In my application unique identifier taken is xpath.
> > i.e. xpath=//img[contains(@src,'https://staticprogressive-
> > dev.mymitchell.com/static/images/menuButton_icon-workqueue.gif')<http://dev.mymitchell.com/static/images/menuButton_icon-workqueue.gif...>]"
>
> > xpath=/html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/td/span/
> > table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/
> > tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a
>
> > Sometime they works fine and sometimes throws error:
>
> >  org.openqa.selenium.NoSuchElementException: Unable to find element
> > with xpath == /html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/
> > td/span/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/
> > tbody/tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a (WARNING:
> > The server did not provide any stacktrace information)
> > Command duration or timeout: 391 milliseconds
>
> > Thanks,
> > Mukesh
> > mrawat...@gmail.com

mukesh rawat

unread,
May 4, 2012, 2:52:15 AM5/4/12
to webdriver
Hi the code is follows:-




<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><link id="appFrameCss" type="text/css"
rel="stylesheet" href="https://staticprogressive-dev.mymitchell.com/
static/include/appFrame.css" /><link id="styleCss" type="text/css"
rel="stylesheet" href="https://staticprogressive-dev.mymitchell.com/
static/include/style.css" /><link id="screenCss" type="text/css"
media="screen" rel="stylesheet" href="https://staticprogressive-
dev.mymitchell.com/static/Framework/include/screen.css" /><link
id="printCss" type="text/css" media="print" rel="stylesheet"
href="https://staticprogressive-dev.mymitchell.com/static/Framework/
include/print.css" />
<title>Mitchell WorkCenter - Welcome</title>
<script type='text/javascript'> var staticURL = 'https://
staticprogressive-dev.mymitchell.com'; </script>
<title>
</title></head>
<body class="appBody" style="height:100%;overflow:hidden"
topmargin="0" leftmargin="0" background="https://staticprogressive-
dev.mymitchell.com/static/images/appFrame_bg-body.gif">
<div id="divPrintArea" class="printarea">
</div>
<form method="post" action="WelcomePage.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__EVENTTARGET" id="__EVENTTARGET" value="" /
>
<input type="hidden" name="__EVENTARGUMENT" id="__EVENTARGUMENT"
value="" />
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/
wEPDwUKLTU1MTkwNjMzMA9kFgJmD2QWBGYPZBYIZg8WAh4EaHJlZgVIaHR0cHM6Ly9zdGF0aWNwcm9ncmVzc2l2ZS1kZXYubXltaXRjaGVsbC5jb20vc3RhdGljL2luY2x1ZGUvYXBwRnJhbWUuY3NzZAIBDxYCHwAFRWh0dHBzOi8vc3RhdGljcHJvZ3Jlc3NpdmUtZGV2Lm15bWl0Y2hlbGwuY29tL3N0YXRpYy9pbmNsdWRlL3N0eWxlLmNzc2QCAg8WAh8ABVBodHRwczovL3N0YXRpY3Byb2dyZXNzaXZlLWRldi5teW1pdGNoZWxsLmNvbS9zdGF0aWMvRnJhbWV3b3JrL2luY2x1ZGUvc2NyZWVuLmNzc2QCAw8WAh8ABU9odHRwczovL3N0YXRpY3Byb2dyZXNzaXZlLWRldi5teW1pdGNoZWxsLmNvbS9zdGF0aWMvRnJhbWV3b3JrL2luY2x1ZGUvcHJpbnQuY3NzZAIBD2QWAgIHD2QWAgIED2QWAmYPZBYCAgEPZBYCAgEPFgIeBFRleHQFggY8dGFibGUgY2VsbHBhZGRpbmc9IjAiIGNlbGxzcGFjaW5nPSIwIiBib3JkZXI9IjAiIHN0eWxlPSJ3aWR0aDo4MCU7aGVpZ2h0OjEwMCU7IGZvbnQtZmFtaWx5OkFyaWFsOyBmb250LXNpemU6MTg7IGNvbG9yOkdyYXk7Ij48dHI
+PHRkIHN0eWxlPSJoZWlnaHQ6MjAlOyIgdmFsaWduPSJtaWRkbGUiIGFsaWduPSJjZW50ZXIiPjxpbWcgc3JjPSJodHRwczovL3N0YXRpY3Byb2dyZXNzaXZlLWRldi5teW1pdGNoZWxsLmNvbS9zdGF0aWMvaW1hZ2VzL21fbG9nb193b3JrYmVuY2guZ2lmIiAvPjxiciAvPjwvdGQ
+PC90cj48dHI
+PHRkPldlbGNvbWUgdG8gdGhlIE1pdGNoZWxsIFdvcmtDZW50ZXIhPC90ZD48L3RyPjx0cj48dGQ
+PGJyIC8+PC90ZD48L3RyPjx0cj48dGQ
+VG8gc2V0IGEgU3RhcnQgUGFnZSB0byBsb2FkIHdoZW4geW91IGVudGVyIFdvcmtDZW50ZXIsIGNsaWNrIG9uIE15IEFjY291bnQgYXQgdGhlIHRvcCBvZiB0aGlzIHBhZ2UsIHRoZW4gY2xpY2sgQ2hhbmdlIFN0YXJ0IFBhZ2UgdG8gY2hhbmdlIHlvdXIgc3RhcnQgcGFnZSBwcmVmZXJlbmNlLjwvdGQ
+PC90cj48dHI+PHRkPjxiciAvPjwvdGQ+PC90cj48dHI
+PHRkPkZvciBtb3JlIGluZm9ybWF0aW9uIG9uIHNldHRpbmcgb3IgY2hhbmdpbmcgeW91ciBTdGFydCBQYWdlLCBjbGljayBIZWxwIGF0IHRoZSB0b3Agb2YgdGhpcyBwYWdlIGFuZCBzZWFyY2ggb24gTXkgQWNjb3VudC48L3RkPjwvdHI
+PHRyPjx0ZCBzdHlsZT0iaGVpZ2h0OjIwJTsiPjxiciAvPjwvdGQ
+PC90cj48L3RhYmxlPmRk3FB5Z1UNeMTQ9Tbyq9w5Yl6MUbU=" />
</div>
 <script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form1'];
if (!theForm) {
theForm = document.form1;
}
function __doPostBack(eventTarget, eventArgument) {
if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
theForm.__EVENTTARGET.value = eventTarget;
theForm.__EVENTARGUMENT.value = eventArgument;
theForm.submit();
}
}
//]]>
</script>
<script src="/static/include/WebForms.js" type="text/javascript"></
script>
<script src="https://staticprogressive-dev.mymitchell.com/static/
jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
<script src="https://staticprogressive-dev.mymitchell.com/static/
jquery/jquery-ui-1.8.custom.min.js" type="text/javascript"></
script><script src="https://staticprogressive-dev.mymitchell.com/
static/include/section.js"></script><script src="/tchs/common/
viewhelp.js"></script>
<link href="https://staticprogressive-dev.mymitchell.com/static/
include/workbench.css" type="text/css" rel="stylesheet">
<script src="https://staticprogressive-dev.mymitchell.com/static/
include/WorkbenchAppFrame.js"></script>
try{
resizeAll();}
catch(e){
}
</script>
<script language='javascript'>
var drop = new Array(20);
var iMenus = 0;
function showHideLayers(oElement,sVis) {
if(oElement!=null) {
if(oElement.style) {
oElement.style.visibility = sVis;
}
}
}
function endMenu() {
var sRet = '</td></tr></table></body></html>';
return sRet;
}
function AddDrop(myFrame) {
try {
drop[iMenus] = myFrame;
iMenus++;
}
catch (ignore) { }
}
function resizeAll()
{
yyfor(var i=0;i<20;i++)

{

try

{

resizeThis(drop[i]);

}

catch(ignore) { }

}

}


function resizeThis(myFrame) {

try {

var oMainTable = eval(myFrame.document.all.Wrapper);


if (oMainTable.clientWidth==null||oMainTable.clientWidth==0) {

setTimeout('resizeThis(document.all.'+myFrame.name+')',10);

} else {


myFrame.resizeTo(oMainTable.clientWidth,oMainTable.clientHeight);

}

}

catch (ignore) { }

}

</script>

<script language='javascript'>

var defaultText = 'Claim Number';


// It will check if there is any input in textbox other than default
text then it should not watermark it.

function checkWatermark()

{

try {

var objtxtClaimSuffix = document.getElementById('txtClaimSuffix');

if(objtxtClaimSuffix != null && objtxtClaimSuffix != 'undefined')

{

if(objtxtClaimSuffix.value != defaultText)

{

objtxtClaimSuffix.focus();

objtxtClaimSuffix.blur();

}

}

}

catch (ignore) { }

}


//This function will watermark on focus and blur events if there is
default text

function waterMark(txt, evt)

{

try {

if(evt.type == 'blur')

{

if(txt.value == defaultText && txt.style.textTransform ==
'uppercase')

{

txt.style.color = 'black';

txt.style.textTransform = 'uppercase';

txt.value = txt.value.toUpperCase();

}


if(txt.value == defaultText || txt.value.length == 0)

{

txt.style.color = 'gray';

txt.value = defaultText;

txt.style.textTransform = 'none';

}

else

{

txt.style.color = 'black';

txt.style.textTransform = 'uppercase';

}

}


if(evt.type == 'focus')

{

if(txt.value == defaultText)

{

txt.style.color = 'black';

txt.value='';

txt.style.textTransform = 'uppercase';

}

else

{

txt.style.color = 'black';

txt.style.textTransform = 'uppercase';

}

}

}

catch (ignore) {}

}


// If textbox has default value or empty then it returns false else
create calling URL

function validClaim()

{

try{

var sClaimSuffixNo = document.getElementById('txtClaimSuffix').value;


if(sClaimSuffixNo == '' || sClaimSuffixNo == 'undefined')

{

return false;

}


if(document.getElementById('txtClaimSuffix').style.color == 'gray' &&
sClaimSuffixNo == defaultText)

{

return false;

}

else

{

sClaimSuffixNo = sClaimSuffixNo.toUpperCase();

parseClaim('');

callSearchUrl();

}

}

catch (ignore) {}

}


function callSearchUrl()

{

try{

var dropDown = document.getElementById('searchDropDown');

var dropDownValue = dropDown.options[dropDown.selectedIndex].value;

var dropDownText = dropDown.options[dropDown.selectedIndex].text;

var sClaimID =
document.getElementById('hidClaimPart').value.toUpperCase();

var sSuffixID =
document.getElementById('hidSuffixPart').value.toUpperCase();

var sUserValue =
document.getElementById('txtClaimSuffix').value.toUpperCase();

window.location.href= dropDownValue +'?CLMNO='+ escape(sClaimID) +
'&SNO=' + escape(sSuffixID) + '&GSCSNO=' + escape(sUserValue) +
'&GSV=' + escape(dropDownText);

//alert (dropDownValue +'?CLMNO='+ sClaimID + '&SUFFIXNO=' + sSuffixID
+ '&UV=' + sUserValue + '&GlobalSearchValue=' + dropDownText);

}

catch (ignore) {}

}


</script><script language="javascript" for="window" event="onload()">

try{

checkWatermark();}

catch(e){

}

</script>


<script type="text/javascript" language="javascript">

// used to store the broacdastMessageWindow and it's current state
once open

var broacdastMessageWindow = null;


// this function controls launching/focus of the New Broadcast Message
window

function LaunchBroadcastMessaging() {

// if there is already a broacdastMessagWindow open

if (broacdastMessageWindow != null && !broacdastMessageWindow.closed)
{

// focus on the window

broacdastMessageWindow.focus();

}

// if there is no window open or the window was closed

else {

// update the variable and open the window

broacdastMessageWindow = window.open('', 'BroadcastMessage',
'height=600px,width=800px,resizable=yes,status=no,location=no,menubar=no,titlebar=no,toolbar=no');


// if the window is blank

if (broacdastMessageWindow.document.forms.length == 0) {

// show a loading message

broacdastMessageWindow.document.write('<table style="width:100%;height:
100%;"><tr><td style="width:100%;vertical-
align:middle;"><center><label>Loading page, one moment please...</
label></center></td></tr></table>');

// open the broadcast messaging url

broacdastMessageWindow.location = location.protocol + '//' +
location.host + '/WorkCenterPlatform/BroadcastMessaging/
BroadcastMessaging.aspx';

}


// focus on the window

broacdastMessageWindow.focus();

}

}

</script>

<script src="/WorkCenterPlatform/ScriptResource.axd?
d=4o25TIF1JIWwJZjAPyppWRNxUkEMR7Jb6n_O9wIDK2LLYgwErIBw2Vwro2cl0EVsJP8ZX44cczWxc_P_JRDPtV7Cc_IM4jeHGNJsg98MfTdXQ1avM5TbKp4-
tAAGwUDEQvEXWzrpO5yqvVQhGhEb_dOOoHqUD86xeOqXMHxQgXbtacLpY-
NRiH54Z1T4F_uA0xwOAbjFVMwIOlRBBP3gvCl6AefdTIrZiMQnmQ2" type="text/
javascript"></script>

<script type="text/javascript">

//<![CDATA[

if (typeof(Sys) === 'undefined') throw new Error('ASP.NET Ajax client-
side framework failed to load.');

//]]>

</script>


<script src="/WorkCenterPlatform/ScriptResource.axd?d=MK4UlzEpkhLls-
BaAjbM-9Fd5D-SRPWpVFdqeo_tOnt1O2jwMy_AhZtCA2my3JcGKHewsqFTFj9I13jXi-
N9qwBh3zNH7y_d5gLk9fcePNwKVAvQnxUJ4dC1qsaBcmftyxEGpFHYDimDD1YqsqwCte9tVIxhcp8CEYC4A6XJlcPF0WZnEmCl58BAttI1"
type="text/javascript"></script>

<script type="text/javascript">

//<![CDATA[

Sys.WebForms.PageRequestManager._initialize('ctl00$ScriptManager',
'form1', [], [], [], 90, 'ctl00');

//]]>

</script>




<div id="divScreenArea" class="screenarea">


<!-- BEGIN Screen Blur -->

<div id="screenBlur" style="BORDER-RIGHT:medium none; PADDING-RIGHT:
0px; BORDER-TOP:medium none; DISPLAY:none; PADDING-LEFT:0px; Z-INDEX:
150; FILTER:alpha(Opacity=35); LEFT:0px; PADDING-BOTTOM:0px; BORDER-
LEFT:medium none; WIDTH:100%; PADDING-TOP:0px; BORDER-BOTTOM:medium
none; POSITION:absolute; TOP:0px; HEIGHT:100%; BACKGROUND-
COLOR:#cccccc">

<iframe allowTransparency="true" frameborder="0" scrolling="no"
width="100%" height="100%" src="javascript:
parent.writeScreenBlur()">

</iframe>

</div>

<!-- END Screen Blur -->

<!-- BEGIN Drag Bar X-->

<div id="DragBar" style="BORDER-RIGHT:medium none; PADDING-RIGHT:0px;
BORDER-TOP:medium none; DISPLAY:none; PADDING-LEFT:0px; Z-INDEX:2;
FILTER:alpha(Opacity=90); LEFT:0px; PADDING-BOTTOM:0px; BORDER-
LEFT:medium none; WIDTH:24px; CURSOR:e-resize; PADDING-TOP:0px; BORDER-
BOTTOM:medium none; POSITION:absolute; TOP:0px; HEIGHT:100%">

<img src="https://staticprogressive-dev.mymitchell.com/static/images/
ctrl_dragbarX.gif" width="24" height="100%"><br>

</div>

<!-- END Drag Bar X -->

<table border="0" width="100%" height="100%" cellpadding="0"
cellspacing="0" style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; PADDING-
BOTTOM: 6px; PADDING-TOP: 6px"

id="Table1">

<tr>

<td>

<table border="0" width="100%" height="100%" cellpadding="0"
cellspacing="0" id="Table2">

<tr>

<td width="100%">

<!-- BEGIN WORKBENCH Header -->


<span id="workBench_presentation"><table cellspacing="0"
cellpadding="0" border="0" width="100%" height="100%">

<tr>

<td width="100%">

<table cellspacing="0" cellpadding="0" border="0" width="100%">

<tr>

<td width="100%">

<table id="appFrame_tbl" class="appFrame" style="WIDTH: 100%"
cellspacing="0" cellpadding="0" border="0">

<tr>

<td class="spacer_NoText" valign="bottom" rowSpan="2">

<img height="23" src="https://staticprogressive-dev.mymitchell.com/
static/images/appFrame_logo-top.gif" width="190" border="0" /><br />

</td>

<td class="spacer_NoText" nowrap align="left">

<table cellspacing="0" cellpadding="0" border="0">

<tr>

<td class="spacer_NoText">

<img src="https://staticprogressive-dev.mymitchell.com/static/images/
spacer_clear.gif" width="3" border="0" /><br />

</td>

<td class="spacer_NoText">

<img src="https://staticprogressive-dev.mymitchell.com/static/images/
spacer_clear.gif" width="1" /><img height="20" src="https://
staticprogressive-dev.mymitchell.com/static/images/icon_appUser.gif"
width="13" border="0" /><br />

</td>

<td class="appFrame_user" noWrap>PCS User</td>

<td width=20 align=center nowrap=true></td>

<td width=100% align=center nowrap=true></td>

</tr>

</table>

</td>

<td class="spacer_NoText" align="left" width="100%">&nbsp;</td>

<td class="spacer_NoText" noWrap align="right">

<table cellspacing="0" cellpadding="0" border="0">

<tr>

<td class="spacer_NoText"><a class="appFunction" href="javascript:var
sPrefix1=location.protocol+'//'+location.host+'/PasswordMgmt/'; var i
= window.open(sPrefix1+'MyAccount.aspx?popup=true%26myLogout=../
logout.aspx','MyAccount','height=600px,width=800px,resizable=yes,status=no,location=no,menubar=no,titlebar=no,toolbar=no');"
><img height="20" src="https://staticprogressive-dev.mymitchell.com/
static/UserManagement/images/icon_appManageAccount.gif" width="14"
border="0" /></a><br /></td>

<td class="appFrame_functions-help" nowrap><a class="appFunction"
href="javascript:var sPrefix1=location.protocol+'//'+location.host+'/
PasswordMgmt/'; var i = window.open(sPrefix1+'MyAccount.aspx?popup=true
%26myLogout=../
logout.aspx','MyAccount','height=600px,width=800px,resizable=yes,status=no,location=no,menubar=no,titlebar=no,toolbar=no');"
>My Account</a></td>

<td class="spacer_NoText"><a class="appFunction" href="javascript:var
i = ViewHelp('~helpcontext~','~productid~', 1033,'');" ><img
height="20" src="https://staticprogressive-dev.mymitchell.com/static/
images/icon_appHelp.gif" width="14" border="0" /></a><br /></td>

<td class="appFrame_functions-help" nowrap><a class="appFunction"
href="javascript:var i = ViewHelp('~helpcontext~','~productid~',
1033,'');" >Help</a></td>

<td class="spacer_NoText"><a class="appFunction" href="/Logout.aspx"
><img height="20" src="https://staticprogressive-dev.mymitchell.com/
static/images/icon_appLogout.gif" width="14" border="0" /></a><br /></
td>

<td class="appFrame_functions-help" nowrap><a class="appFunction"
href="/Logout.aspx" >Logout</a></td>

</tr>

</table>

</td>

<td class="spacer_NoText">&nbsp;</td>

</tr>

<tr>

<td background="https://staticprogressive-dev.mymitchell.com/static/
images/appFrame_top-stretch.gif" colSpan="3">

<img height="3" src="https://staticprogressive-dev.mymitchell.com/
static/images/appFrame_top-stretch.gif" width="1" /><br />

</td>

<td>
<img height="3" src="https://staticprogressive-dev.mymitchell.com/
static/images/appFrame_top-right-corner.gif" width="10" /><br />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td width="100%">
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td width="100%">
<table id="appFrame_Menu_tbl" class="appFrame" cellspacing="0"
cellpadding="0" border="0">
<tr>
<td height="100%">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
appFrame_menu-leftcap.gif" width="10" height="100%" /><br /> </td>
<td valign="top" background="https://staticprogressive-
dev.mymitchell.com/static/images/appFrame_menu-stretch.gif">
<img height="32" src="https://staticprogressive-dev.mymitchell.com/
static/images/appFrame_logo-bottom.gif" width="190" border="0" /><br /
>
</td>
<td valign="middle" align="left" width="100%" background="https://
staticprogressive-dev.mymitchell.com/static/images/appFrame_menu-
stretch.gif">
<table height="10" width="100%" cellspacing="0" cellpadding="0"
border="0">
<tr>
<td width="100%" valign="top">
<div id="menu" style="white-space:nowrap; position:relative; top:-1px;
left:0px; z-index:99; WIDTH: 100%; ">
<ul style="width:16px;">
<li onMouseOver="showMenuElements('HomeBorderLeft','HomeBorderRight');
document.all.HomeMenu.style.backgroundImage = 'url(https://
staticprogressive-dev.mymitchell.com/static/images/navStretch.gif)';"
onMouseOut="hideMenuElements('HomeBorderLeft','HomeBorderRight');
document.all.HomeMenu.style.backgroundImage = 'url(https://
staticprogressive-dev.mymitchell.com/static/images/appFrame_menu-
stretch.gif)'; ">
<a href="#" onclick="location.href='/Workbench.aspx';">
<h2 id="HomeMenu" style=" cursor: default;">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderLeft.gif" align="middle" style="VISIBILITY:hidden"
id="HomeBorderLeft" />
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
menuButton_icon-home.gif" align="middle">&nbsp;Home
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderRight.gif" align="middle" style="VISIBILITY:hidden"
id="HomeBorderRight">
</h2>
</a>
</li>
</ul>

<ul style="width:24px;">
<li
onMouseOver="showMenuElements('SearchBorderLeft','SearchBorderRight','SearchMenuMain','SearchFrame');document.all.SearchMenu.style.backgroundImage
= 'url(https://staticprogressive-dev.mymitchell.com/static/images/
navStretch.gif)';"
onMouseOut="hideMenuElements('SearchBorderLeft','SearchBorderRight','SearchMenuMain','SearchFrame');
document.all.SearchMenu.style.backgroundImage = 'url(https://
staticprogressive-dev.mymitchell.com/static/images/appFrame_menu-
stretch.gif)'; ">
<h2 id="SearchMenu" style=" cursor: default;">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderLeft.gif" align="middle" style="VISIBILITY:hidden"
id="SearchBorderLeft">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
menuButton_icon-search.gif" align="middle">&nbsp;Search<img
src="https://staticprogressive-dev.mymitchell.com/static/images/
menuButton_arrow.gif" align="middle">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderRight.gif" align="middle" style="VISIBILITY:hidden"
id="SearchBorderRight">
</h2>
<div id="SearchMenuMain" style="VISIBILITY:hidden">
<IFRAME id="SearchFrame" class="shim" style="height:112px; width:
77px;" src="https://staticprogressive-dev.mymitchell.com/static/images/
spacer_clear.gif"></IFRAME>
<ul style="padding:1px 0px 0px 0px;">
<li class="menuItemMiddle" style="WIDTH=77px"><a href="/UserInfo/
UIResourceLookup/ResourceTool.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Resources&nbsp;</
a></li>
<li class="menuItemMiddle" style="WIDTH=77px"><a href="/
AppraisalAssignment/SearchAssignment.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Assignments&nbsp;</
a></li>
<li class="menuItemMiddle" style="WIDTH=77px"><a href="/CARR/
CARREstimates/EstimateSearch.aspx"><img src="https://staticprogressive-
dev.mymitchell.com/static/images/spacer_clear.gif" height="21"
width="5" border="0" align="absmiddle">Estimates&nbsp;</a></li>
<li class="menuItemBottom" style="WIDTH=77px"><a href="/
WorkCenterPlatform/ClaimsList/ClaimsList.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Claims&nbsp;</a></
li>
</ul>
</div>
</li>
</ul>


<ul style="width:40px;">
 <li
onMouseOver="showMenuElements('WorkQueueBorderLeft','WorkQueueBorderRight','WorkQueueMenuMain','WorkQueueFrame');document.all.WorkQueueMenu.style.backgroundImage
= 'url(https://staticprogressive-dev.mymitchell.com/static/images/
navStretch.gif)';"
onMouseOut="hideMenuElements('WorkQueueBorderLeft','WorkQueueBorderRight','WorkQueueMenuMain','WorkQueueFrame');
document.all.WorkQueueMenu.style.backgroundImage = 'url(https://
staticprogressive-dev.mymitchell.com/static/images/appFrame_menu-
stretch.gif)'; ">
 <h2 id="WorkQueueMenu" style=" cursor: default;">
  <img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderLeft.gif" align="middle" style="VISIBILITY:hidden"
id="WorkQueueBorderLeft">

<img src="https://staticprogressive-dev.mymitchell.com/static/images/
menuButton_icon-workqueue.gif" align="middle">&nbsp;Work Queue

<img src="https://staticprogressive-dev.mymitchell.com/static/images/
menuButton_arrow.gif" align="middle">
<img src="https://staticprogressive-dev.mymitchell.com/static/images/
navBorderRight.gif" align="middle" style="VISIBILITY:hidden"
id="WorkQueueBorderRight">
  </h2>

<div id="WorkQueueMenuMain" style="VISIBILITY:hidden">
 <IFRAME id="WorkQueueFrame" class="shim" style="height:140px; width:
120px;" src="https://staticprogressive-dev.mymitchell.com/static/
images/spacer_clear.gif"></IFRAME>
 <ul style="padding:1px 0px 0px 0px;">
<li class="menuItemMiddle" style="WIDTH=120px"><a href="/
AppraisalAssignment/ManageWorkqueue.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Assignments&nbsp;</
a></li>
<li class="menuItemMiddle" style="WIDTH=120px"><a href="/
AppraisalAssignment/SchedulingBoard.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Scheduling
Board&nbsp;</a></li>
<li class="menuItemMiddle" style="WIDTH=120px"><a href="/CARR/
CARRWorkQueue/WorkQueue.aspx"><img src="https://staticprogressive-
dev.mymitchell.com/static/images/spacer_clear.gif" height="21"
width="5" border="0" align="absmiddle">Assigned Estimates&nbsp;</a></
li>
<li class="menuItemMiddle" style="WIDTH=120px"><a href="/CARR/
CARRWorkQueue/UnassignedWorkQueue.aspx"><img src="https://
staticprogressive-dev.mymitchell.com/static/images/spacer_clear.gif"
height="21" width="5" border="0" align="absmiddle">Unassigned
Estimates&nbsp;</a></li>
<li class="menuItemBottom" style="WIDTH=120px"><a href="/
WorkCenterPlatform/IntegratedWorkView/IntegratedWorkView.aspx"><img
src="https://staticprogressive-dev.mymitchell.com/static/images/
spacer_clear.gif" height="21" width="5" border="0"
align="absmiddle">Tasks&nbsp;</a></li>
 </ul>
 </div>
 </li>
 </ul>

Last 2 <ul>(starts from <ul style="width:40px;"> )   are the code for
where i have to perform actions;
Xpath using to identify the element are-

 1. for menu-Work Queue
2. for sub menu- Tasks
xpath=/html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/td/
span/
table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/
tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a

I have to click on MouseOverMenu.

Thanks
Mukesh

On May 3, 9:01 pm, Mike Riley <lvskip...@cox.net> wrote:
> Please show your code where you are using the XPath locators.
>
> Any time some says "they sometimes work and sometimes don't" makes me
> believe you are not waiting for them to show up, so that sometimes they
> show up quickly enough and sometimes the browser doesn't render them in
> time.  A timeout of 391ms is very short.
>
> Another thing is that your second XPath is an absolute path that would be
> very fragile.  One minor change to that web page would break it.  The first
> one is much more robust, because it could only break if a different image
> path was used.  I would seriously look at improving that second XPath to be
> just "//a[<something>]" so it is not so fragile.
>
> Mike
>
>
>
>
>
>
>
> On Thursday, May 3, 2012 2:31:47 AM UTC-7, mukesh rawat wrote:
>
> > HI,
>
> > In my application unique identifier taken is xpath.
> > i.e. xpath=//img[contains(@src,'https://staticprogressive-
> > dev.mymitchell.com/static/images/menuButton_icon-workqueue.gif')<http://dev.mymitchell.com/static/images/menuButton_icon-workqueue.gif...>]"
>
> > xpath=/html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/td/span/
> > table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/tbody/
> > tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a
>
> > Sometime they works fine and sometimes throws error:
>
> >  org.openqa.selenium.NoSuchElementException: Unable to find element
> > with xpath == /html/body/form/div[2]/table/tbody/tr/td/table/tbody/tr/
> > td/span/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td/table/
> > tbody/tr/td[3]/table/tbody/tr/td/div/ul[3]/li/div/ul/li[5]/a (WARNING:
> > The server did not provide any stacktrace information)
> > Command duration or timeout: 391 milliseconds
>
> > Thanks,
> > Mukesh
> > mrawat...@gmail.com

Julia S.S

unread,
May 7, 2012, 7:01:24 AM5/7/12
to webd...@googlegroups.com
Also when 'it does not work' which error do you get? Something on the line of "element not found" or "XPath expression is nor valid or does not resolve into a valid element"?

Regards,
Julia 

mukesh rawat

unread,
May 8, 2012, 8:15:17 AM5/8/12
to webdriver

It gives " Element not visisble" some times

Mark Collin

unread,
May 8, 2012, 8:48:06 AM5/8/12
to webd...@googlegroups.com
That is nothing to do with the XPath, the XPath is working correctly and
finding the element. The problem is that the element is not visible (the
clue is in the exception) and WebDriver cannot interact with elements that
are not visible. This is because WebDriver emulates an end user and an end
user cannot interact with elements that are not visible.

You need to work out why the element is not visible and make it visible, or
you need to wait for the element to become visible before interacting with
it. Try setting:

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

after instantiating the driver object and see if this fixes your problem.

darrell

unread,
May 15, 2012, 8:54:54 AM5/15/12
to webdriver
The facts:

- Some times the code works with no changes
- When it fails the element is not visible

This means that something is either making the element invisible or
the page loads with the element invisible and javascript changes the
element to be visible. It is not uncommon to load a page with elements
invisible. After loading javascript code will determine whether or not
to change an element to visible. If your Selenium code runs fast
enough, it might try to interact with the element before the
javascript can make it visible.

The easiest solution is use a method will waits for the element to
become visible. Your original code would have been:

// find the element
// click the element

The new code will be:

        // find the element
// wait for the element to be visible
        // click the element

Darrell
Reply all
Reply to author
Forward
0 new messages