简体   繁体   中英

Get InnertText from input with pupperteer-sharp using C# and XPath

How to get the innerText from a <input> using XPath?

I have this to work but with CSS, but it do not work for me with XPath

    IElementHandle ha = await page.QuerySelectorAsync(xpath);
    IJSHandle ith = await ha.GetPropertyAsync("value");
    string val = ith.RemoteObject.Value.ToString();

The following works for me:

using PuppeteerSharp;

using var browserFetcher = new BrowserFetcher();
await browserFetcher.DownloadAsync();
await using var browser = await Puppeteer.LaunchAsync(new LaunchOptions { Headless = true });

using (var page = await browser.NewPageAsync())
{
    await page.GoToAsync("http://www.google.de/");
    var input = (await page.XPathAsync("/html/body/div[1]/div[3]/form/div[1]/div[1]/div[4]/center/input[1]"))[0];
    var ith = await input.GetPropertyAsync("value");
    var val = ith.RemoteObject.Value.ToString();
    Console.Write(val);
}

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