【问题标题】:Element is no longer valid元素不再有效
【发布时间】:2016-06-16 10:38:57
【问题描述】:

我遇到了 Python 和 Selenium 的问题。

我想点击一个链接,这是我的 Py 代码:

toubao_luru_xpath='//div[87]/xml/items/item[2]/item[@path=policynewbiz/inputapplication/chooseproduct.jsp]'
#url=policynewbiz/inputapplication/chooseproduct.jsp
print WebDriverWait(browser,10).until(EC.presence_of_element_located((By.XPATH,toubao_luru_xpath)))
print browser.find_element_by_xpath(toubao_luru_xpath)
#print browser.find_element_by_xpath(toubao_luru_xpath).click()

错误是:

文件 "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", 第 80 行,直到 raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Yes,

这是 HTML 代码:

<html>
<DIV style="DISPLAY: none"><xml id=__menu>
<items>
    <item  name="quotation"  label="&#25955;&#21333;&#25253;&#20215;" >
       <item  name="input"  label="&#24405;&#20837;"  path="policyquotation/createquotation/chooseproduct.jsp"  icon="../image/icon/1.gif"  visible="false" ></item>
        <item  name="quotationinput"  label="&#24405;&#20837;"  icon="../image/icon/1.gif"  visible="false"  command="commandCreateQuotationTemplate" ></item>
        <item  name="quotationinput2014"  label="&#24405;&#20837;"  path="policyquotation_v2/chooseproduct2014.jsp"  icon="../image/icon/1.gif" ></item>
        <item  name="enterquotation"  label="enterquotation"  visible="false" ></item>
        <item  name="queryQuotation"  label="&#26597;&#35810;"  path="policyquotation/qryquotationlist.jsp"  icon="../image/icon/2.gif"  visible="false" ></item>
        <item  name="queryQuotation2"  label="&#26597;&#35810;"  path="policyquotation_v2/qryquotationlist.jsp"  icon="../image/icon/2.gif" ></item>
        <item  name="packageWork"  label="&#22871;&#39184;&#25351;&#23450;"  path="policyquotation/package-manage-work.jsp"  icon="../image/icon/3.gif"  visible="false" ></item>
        <item  name="querypackage"  label="&#22871;&#39184;&#31649;&#29702;"  path="policyquotation/query-package-list.jsp"  icon="../image/icon/4.gif"  visible="false" ></item>
        <item  name="quotationfollow"  label="&#25253;&#20215;&#36319;&#36827;"  path="policyquotation/followquotation.jsp"  icon="../image/icon/5.gif"  visible="false" ></item>
        <item  name="entererror"  label="entererror"  path="error.jsp"  visible="false" ></item>
        <item  name="quotationfollownew"  label="&#25253;&#20215;&#36319;&#36827;"  path="policyquotation_v2/followquotation.jsp"  icon="../image/icon/5.gif"  visible="false" ></item>
    </item>
    <item  name="application"  label="&#25237;&#20445;" >
        <item  name="input"  label="&#24405;&#20837;"  path="policynewbiz/inputapplication/chooseproduct.jsp"  icon="../image/icon/1.gif" ></item>
</html>

我想点击的最后一个&lt;item&gt;

【问题讨论】:

  • 使用这个 xPath //item[@path='policynewbiz/inputapplication/chooseproduct.jsp']
  • 提供html目标元素的代码

标签: python selenium


【解决方案1】:

这应该可行。鉴于您提供的 HTML,它是独一无二的,我假设没有两个指向同一个 URL 的链接,所以它应该是好的。

driver.find_element_by_css_selector("item[path='policynewbiz/inputapplication/chooseproduct.jsp']").click()

【讨论】:

  • 用户使用浏览器而不是驱动程序来实例化它。 browser.find_element_by_css_selector("item[path='policynewbiz/inputapplication/chooseproduct.jsp']").click()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-04
  • 1970-01-01
  • 2012-10-05
  • 1970-01-01
  • 1970-01-01
  • 2018-04-22
相关资源
最近更新 更多