Selenium :链接的Xpath在刷新页面时更改,运行代码时会显示"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element //*[@id='yui-gen79'] not found".
如何处理此错误?
第一:
//*[@id='yui-gen79']之后
//*[@id='yui-gen98']页码
<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>发布于 2013-09-24 13:58:52
使用动态生成的元素ids,有时我发现您可以使用contains和一个更长的xpath定位器来匹配该元素。在示例代码中,看起来只有一个锚点元素有一个id属性,其中包含文本"yui-gen“,因此我建议尝试
//a[contains(@id, 'yui-gen')] https://sqa.stackexchange.com/questions/6855
复制相似问题