【问题标题】:Copy text from website using Selenium for python使用 Selenium for python 从网站复制文本
【发布时间】:2018-01-03 00:40:39
【问题描述】:

我正在尝试使用以下代码从网站复制文本,我希望它自动单击表格末尾的“NEXT”按钮,而不单击它,代码工作得很好但是当我添加最后一个点击它的行会给出错误:

“消息:元素不再附加到 DOM Stacktrace:在 fxdriver.cache.getElementAt (资源://fxdriver/modules/web-element-cache.js:9354) 在 Utils.getElementAt (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver@googlecode.com/components/command-processor.js:8978) 在 WebElement.getElementText (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver@googlecode.com/components/command-processor.js:11965) 在 DelayedCommand.prototype.executeInternal_/h (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver@googlecode.com/components/command-processor.js:12534) 在 DelayedCommand.prototype.executeInternal_ (file:///c:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver@googlecode.com/components/command-processor.js:12539) 在 DelayedCommand.prototype.execute/

我使用的代码是:

driver = webdriver.Firefox()
driver.get("https://it.website.com/Statistics")
wait = ui.WebDriverWait(driver, 10)
wait.until(page_is_loaded)
Next_first = 0
Next_first = driver.find_elements_by_id("next")[0]
data_vector [i]=driver.find_elements_by_class_name("tn")[i].text
Next_first.click()

虽然网站代码是:

<tr>
  <td class="tn"> text
  </td>
  <table class="table class" id="table id">
    <thead>...code for table title...
    </thead>
    <tbody>
      <tr>
        <td class="tn">data
        </td>
      </tr>
    </tbody>
    <dd>
      <a class="option clickable" id="next" data-page="1">NEXT</a>
    </dd>
</tr>

【问题讨论】:

  • 你的代码没有任何意义,它甚至不会编译。

标签: selenium


【解决方案1】:

除了 html 源之外,还有更多的东西,比如 javascript? 因为输入可以被javascript分离,这意味着你必须等待它正确加载(driver.implicitly_wait(#seconds)

here“隐式等待”说明的链接

第二种解决方案可能是您必须在测试之前清除 webdriver 的缓存/cookies,描述为here

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2018-04-13
    • 2020-10-31
    • 1970-01-01
    • 2020-12-18
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 2023-03-10
    相关资源
    最近更新 更多