首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Selenium :在刷新页面时更改链接的Xpath

Selenium :在刷新页面时更改链接的Xpath
EN

Stack Exchange QA用户
提问于 2013-09-24 05:51:35
回答 1查看 1.3K关注 0票数 4

Selenium :链接的Xpath在刷新页面时更改,运行代码时会显示"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Element //*[@id='yui-gen79'] not found".

如何处理此错误?

第一:

代码语言:javascript
复制
//*[@id='yui-gen79']

之后

代码语言:javascript
复制
//*[@id='yui-gen98']

页码

代码语言:javascript
复制
<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>
EN

回答 1

Stack Exchange QA用户

回答已采纳

发布于 2013-09-24 13:58:52

使用动态生成的元素ids,有时我发现您可以使用contains和一个更长的xpath定位器来匹配该元素。在示例代码中,看起来只有一个锚点元素有一个id属性,其中包含文本"yui-gen“,因此我建议尝试

代码语言:javascript
复制
//a[contains(@id, 'yui-gen')] 
票数 1
EN
页面原文内容由Stack Exchange QA提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://sqa.stackexchange.com/questions/6855

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档