How do I get the inner text of an element that has been click?
string xplast = "//button[@id='test']";
IElementHandle last = await ((IPage)page).WaitForXPathAsync(xplast);
await last.FocusAsync();
await last.ClickAsync();
string innertext = (await last.GetInnerTextFromElement()).ToString()
is there a way to do something like this? string innertext = (await last.GetInnerTextFromElement()).ToString()
I have now tested that var text = (await last.GetPropertyAsync("innerText")).RemoteObject.Value.ToString();
works fine, at least here on Windows.
If you'd prefer a strongly typed experience then PuppeteerSharp.Dom provides a set of extensions to PuppeteerSharp
.
Install PuppeteerSharp.Dom from Nuget.org
then you can use the strongly typed extensions.
// Add using PuppeteerSharp.Dom; to access WaitForXPathAsync<T>
string xplast = "//button[@id='test']";
var last = await page.WaitForXPathAsync<HtmlButtonElement>(xplast);
await last.FocusAsync();
await last.ClickAsync();
var innerText = await last.GetInnerTextAsync();
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.