如何获取多个链接下类标签,HTML包含多个多类标签=“blog-item-wrap”每个标签包含标签。需要获取类标签下的所有href链接
<div class="blog-item-wrap">
<a href="https://website.com/data-wrangling-with/" title="Data
Wrangling with JavaScript">
</a>
</div>
<div .... >
<div class="blog-item-wrap">
<a href="https://website.com/data-wrangling-with/" title="Data
Wrangling with JavaScript">
</a>
</div>
</div>
使用它并得到错误:
StaleElementReferenceError: stale element reference: element is not attached to the page document
browser.findElement(By.xpath('//*[@class="blog-item-wrap"]/a')).then(res => { res.getText().then(text => { console.log('text', text); }).catch(err => { console.log('err', err); });
最佳答案
你应该在所有元素上使用 getAttribute("href")
driver.findElements(By.xpath('//*[@class="blog-item-wrap"]/a'))
.
然后使用 getAttribute("href")
迭代列表。
你应该考虑使用async
...
希望对你有帮助!
关于javascript - webdriver node js在类标签下获取多个链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53803828/