我尝试使用以下代码从网站复制文字,我希望它能够自动点击" NEXT"表格末尾的按钮,没有点击它,代码工作得很好但是当我添加最后一行来点击它时会出现错误:
"消息:元素不再附加到DOM Stacktrace:at 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) at 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 /< (文件:/// C:/users/user/appdata/local/temp/tmpa7dvts/extensions/fxdriver@googlecode.com/components/command-processor.js:12481)"
我使用的代码是:
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>