简体   繁体   中英

How to get entire page source using selenium and nodejs? driver.page_source is returning undefined

Unable to fetch entire page source using selenium web driver with node js

I have tried using driver.page_source but in console, I get undefined as return

if(this.driver.findElement(By.id("ap_error_page_message")).isDisplayed()){
        console.log(this.driver.page_source);
    }

in results, I'm getting > undefined I expect the output as source code of current webpage

You could try innerHTML or outerHTML on the body or maybe even the html tag, like this:

const pageSource = await driver.wait(until.elementLocated(By.css('body')), timeoutMS).getAttribute('innerHTML');
console.log('pageSource: ', pageSource);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM