microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.47k stars 235 forks source link

How I can use QuerySelectorAllAsync for iFrame? #2163

Closed zydjohnHotmail closed 2 years ago

zydjohnHotmail commented 2 years ago

Your question

Hello: I can use QuerySelectorAllAsync to get a collection of elements for a web page without iframe. However, now I have to parse a HTML table inside a iframe, there are a lot of table rows, which has the 'tr' elements. If I use var iframe = page.FrameLocator("#frameID"); then, how I can get all the table rows, those element has with 'tr' attribute? I can't find any example on this topic. For the web page without iframe, I can use the following statement: var trs = await page.QuerySelectorAllAsync("tr.class"); But in iframe, how I can return a collection of elements? Please advise, Thanks,

mxschmitt commented 2 years ago

Essentially this would mean that you want to loop over the rows (tr) and then over the columns td. This guide should help you with that: https://playwright.dev/dotnet/docs/locators

We discourage using QuerySelector/All, see here: https://playwright.dev/dotnet/docs/locators#locator-vs-elementhandle

zydjohnHotmail commented 2 years ago

OK. Thanks!