[英]How to get text of an HTML-Element with Selenium/Node.js
不幸的是,我在 stackoverflow 上沒有找到解決我的問題的任何現有解決方案。 所以,有人可以幫忙。
我想獲取 html 元素的文本。 我試過這個:
var element = driver.findElement(webdriver.By.className("credits")).getText();
console.log(element);
不幸的是,這到目前為止還沒有奏效。
有人發布了一個答案並在它幾秒鍾后將其刪除......無論如何還是謝謝你:
對於您的信息,這對我來說很好用:
var textPromise = driver.findElement(webdriver.By.className("credits")).getText();
textPromise.then((text) => {
console.log(text);
});
如果您在異步函數中,請嘗試以下操作:
var element = await driver.findElement(webdriver.By.className("credits")).getText();
console.log(element);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.