Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Selenium RC: Xpath of the link is changed when I refresh the page, and when I run the code it shows "Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element //*[@id='yui-gen79'] not found".

How do I handle this error?

First:

//*[@id='yui-gen79']

After

//*[@id='yui-gen98']

Page code

<document>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<body id="Share" class="yui-skin-default alfresco-share js">
<div/>
<div id="overlay" style="display: none; position: absolute; top: 0px; left: 0px; z-index: 90; width: 100%;">
<div id="lightbox" style="display: none; position: absolute; z-index: 100;">
<span class="yui-resize-status"/>
<span class="yui-resize-status"/>
<span class="yui-resize-status"/>
<span class="yui-resize-status"/>
<div id="page_x002e_component-2-2_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default-metadataTooltip" class="yui-module yui-overlay yui-tt yui-overlay-hidden" style="z-index: 2; visibility: hidden;">
<div id="page_x002e_component-2-2_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default-previewTooltip" class="yui-module yui-overlay yui-tt yui-overlay-hidden" style="z-index: 2; width: 108px; visibility: hidden;">
<iframe id="_yuiResizeMonitor" title="Text Resize Monitor" tabindex="-1" role="presentation" style="position: absolute; visibility: visible; background-color: transparent; border-width: 0px; width: 2em; height: 2em; left: 0px; top: -33px;"/>
<div class="sticky-wrapper">
<div id="doc3">
<div id="alf-hd">
<div id="alf-full-width">
<div id="bd">
<div class="yui-gd grid columnSize2">
<div class="yui-u first column1">
<div id="page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard">
<div id="page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default">
<script type="text/javascript">//<![CDATA[ (function() {    new Alfresco.dashlet.MySites("page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default").setOptions(    {       imapEnabled: false,       listSize: 100    }).setMessages({"empty.title": "Quickly access your sites", "filter.favSites": "My Favorites", "filter.all": "All", "empty.description": "A site is a project area where you can share and discuss content with other site members.", "dashlet.help": "<p>Sites are project areas where you collaborate with others, sharing content and working on it together. This dashlet lists the sites you belong to. You can filter this list to show only your favorite sites.<\/p><p>From here you can:<ul><li>Navigate to a site<\/li><li>Create a new site<\/li><li>Delete a site if you are the site manager<\/li><li>Mark a site as a favorite so that it shows in the Sites menu for easy access<\/li><\/ul><\/p>", "link.deleteSite": "Delete", "link.createSite": "Create Site", "header": "My Sites", "empty.description.sample-site": "We've included a sample site for you. Use this to explore the features in Alfresco Team."});    new Alfresco.widget.DashletResizer("page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default", "page.component-1-1.user~sf-er-ro~dashboard#default");    new Alfresco.widget.DashletTitleBarActions("page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default").setOptions(    {       actions:       [          {             cssClass: "help",             bubbleOnClick:             {                message: "<p\>Sites are project areas where you collaborate with others, sharing content and working on it together. This dashlet lists the sites you belong to. You can filter this list to show only your favorite sites.</p\><p\>From here you can:<ul\><li\>Navigate to a site</li\><li\>Create a new site</li\><li\>Delete a site if you are the site manager</li\><li\>Mark a site as a favorite so that it shows in the Sites menu for easy access</li\></ul\></p\>"             },             tooltip: "Display help for this dashlet"          }       ]    }); })(); //]]></script>
<div id="yui-gen18" class="dashlet my-sites resizable yui-resize">
<div class="title">My Sites</div>
<div class="toolbar flat-button">
<div class="titleBarActions" style="opacity: 1;">
<div id="page_x002e_component-1-1_x002e_user_x007e_sf-er-ro_x007e_dashboard_x0023_default-sites" class="body scrollableList yui-dt">
<div class="yui-dt-mask" style="display: none;"/>
<table id="yuievtautoid-0" summary="">
<colgroup>
<thead>
<tbody class="yui-dt-message" style="display: none;">
<tbody class="yui-dt-data" tabindex="0" style="">
<tr id="yui-rec72" class="yui-dt-rec yui-dt-first yui-dt-last yui-dt-even yui-dt-highlighted" style="">
<td id="yui-gen106" class="yui-dt12-col-icon yui-dt-col-icon yui-dt-first" headers="yui-dt12-th-icon " style="width: 52px;">
<td id="yui-gen88" class="yui-dt12-col-detail yui-dt-col-detail" headers="yui-dt12-th-detail ">
<div id="yui-gen87" class="yui-dt-liner">
<h3 id="yui-gen92" class="site-title">
<a id="yui-gen98" class="theme-color-1" href="/qa/share/page/site/pfsa/dashboard">pfsa</a>
</h3>
<div id="yui-gen89" class="detail">
<div id="yui-gen86" class="detail detail-social">
</div>
</td>
<td class="yui-dt12-col-actions yui-dt-col-actions yui-dt-last" headers="yui-dt12-th-actions " style="width: 24px;">
</tr>
</tbody>
</table>
</div>
<div id="yui-gen56" class="yui-resize-handle yui-resize-handle-b">
</div>
</div>
</div>
<div id="page_x002e_component-1-2_x002e_user_x007e_sf-er-ro_x007e_dashboard">
<div id="unbound-region-component-1-3"/>
<div id="unbound-region-component-1-4"/>
<div id="unbound-region-component-1-5"/>
</div>
<div class="yui-u column2">
</div>
</div>
<div id="alf-id6" class="yui-module yui-overlay" style="z-index: 2; width: 30em; left: 20px; top: 10px;">
<div id="alf-id7" class="yui-module yui-overlay" style="z-index: 2; width: 30em; left: 20px; top: 221px;">
<div id="alf-id8" class="yui-module yui-overlay" style="z-index: 2; width: 30em; left: 436px; top: 10px;">
<div id="alf-id9" class="yui-module yui-overlay" style="z-index: 2; width: 30em; left: 436px; top: 205px;">
</div>
<div class="sticky-push"/>
</div>
<div class="sticky-footer">
<div id="alfresco-yuiloader"/>
<script type="text/javascript">//<![CDATA[       Alfresco.util.YUILoaderHelper.loadComponents(true);       if (Alfresco.constants.PORTLET)       {          YUIDom.addClass(document.body, "yui-skin-default alfresco-share");       }    //]]></script>
</body>
</html>
</document>
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

With dynamically generated element ids, sometimes I find that you can use contains along with a longer xpath locator to match the element. In the sample code provided it looks like only a single anchor element has an id attribute that contains the text "yui-gen" so I would suggest trying

//a[contains(@id, 'yui-gen')] 
share|improve this answer
1  
or //a[starts-with(@id, 'yui-gen')] to be more precise. –  Suchit Parikh Sep 24 '13 at 16:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.