无法在浏览器中为特定链接编写xpath

时间:2015-07-31 08:59:43

标签: python selenium pycharm

我的应用程序中有一个链接,我需要在pycharm中编写脚本,请找到链接的绝对xpath,如下所示:

HTML脚本:

<div id="gwt-uid-71" class="gwt-Label GCBQC1SDGLH GCBQC1SDBLH">FINDINGS</div>

和脚本:

Wait Until Page Contains Element    xpath=//div [contains(@class,'gwt-Label GCBQC1SDGLH GCBQC1SDBLH') and text()[contains(.,'FINDINGS')]]
Click Element    xpath=//div [contains(@class,'gwt-Label GCBQC1SDGLH GCBQC1SDBLH') and text()[contains(.,'FINDINGS')]]

但是当我执行上面的脚本时,我收到以下错误:

  

消息:StaleElementReferenceException:消息:元素不再存在   附加到DOM Stacktrace:       在fxdriver.cache.getElementAt(资源://fxdriver/modules/web-element-cache.js:9351)       在Utils.getElementAt(file:/// c:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:8942)       at fxdriver.preconditions.visible(file:/// c:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:9980 )       在DelayedCommand.prototype.checkPreconditions_(file:/// c:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12626 )       在DelayedCommand.prototype.executeInternal_ / h(file:/// c:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js :12643)       在DelayedCommand.prototype.executeInternal_(file:/// c:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12648 )       在DelayedCommand.prototype.execute /&lt; (文件:/// C:/users/nav/appdata/local/temp/tmpnvucai/webdriver-py-profilecopy/extensions/fxdriver@googlecode.com/components/command-processor.js:12590)

1 个答案:

答案 0 :(得分:0)

该类是通用的还是静态的?它改变了吗?因为正如你所说,你想找到

<div id="gwt-uid-71" class="gwt-Label GCBQC1SDGLH GCBQC1SDBLH">FINDINGS</div> <div class="GCBQC1SDCLH"/> 

这与您发布的xpath不匹配

.//*[@class='gwt-Label GP5LRU5DCNH GP5LRU5DNMH'][text()='FINDINGS']

因为班级不同。

如果类始终相同,则正确的xpath将为:

//div [contains(@class,'gwt-Label GCBQC1SDGLH GCBQC1SDBLH') and text()[contains(.,'FINDINGS')]]

这对你有用吗?