playwright-java icon indicating copy to clipboard operation
playwright-java copied to clipboard

[Question] How can I get the text of <td> inside <table>?

Open NICOGTZL opened this issue 2 years ago • 2 comments

Hello, I'm trying to get a code to verify my session, but I couldn't do it, the code I have to get is 5 characters code, in this case: HC6TJ which is inside of

html statement.

I've tried to copy the xpath of this

, using it in a locator with .textContent(); but this error occured:

WHAT I'VE TRIED:

String emailCode = page3.locator("xpath=/html/body/center[1]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/table[3]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td")
.textContent().replaceAll(" ", "");

System.out.println(emailCode);

ERROR:

Caused by: com.microsoft.playwright.TimeoutError: Error {
  message='Timeout 30000ms exceeded.
=========================== logs ===========================
waiting for selector "xpath=/html/body/center[1]/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[1]/td/table/tbody/tr[2]/td/table[3]/tbody/tr/td/table/tbody/tr/td/table/tbody/tr/td"
============================================================
  name='TimeoutError
  stack='TimeoutError: Timeout 30000ms exceeded.
=========================== logs ===========================

THE HTML TABLE GROUP.

<table width="100%" border="0" cellspacing="0" cellpadding="0">
				<tbody><tr>
					<td class="pb-70 mpb-50" style="padding-bottom: 70px;">
						<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#17191c">
							<tbody><tr>
								<td class="py-30 px-56" style="padding-top: 30px; padding-bottom: 30px; padding-left: 56px; padding-right: 56px;">
									<table width="100%" border="0" cellspacing="0" cellpadding="0">
																				<tbody><tr>
											<td class="title-48 c-blue1 fw-b a-center" style="font-size:48px; line-height:52px; font-family:Arial, sans-serif, 'Motiva Sans'; color:#3a9aed; font-weight:bold; text-align:center;">
												HC6TJ											</td>
										</tr>
									</tbody></table>
								</td>
							</tr>
						</tbody></table>
					</td>
				</tr>
			</tbody></table>

NICOGTZL avatar Sep 13 '22 07:09 NICOGTZL

We'd recommend Playwright Codegen to find a better selector, since your selector does not follow the best practises.

Also see here how to debug selectors.

mxschmitt avatar Sep 13 '22 15:09 mxschmitt

Is Playwright Codegen available for Java?

Yes, the link I sent you is about how to use it with Maven.

Usually it does not work because Playwright does not find the element. Lets see what Playwright codegen will emit?

mxschmitt avatar Sep 13 '22 17:09 mxschmitt

Closing as part of the triage process since it seemed stale or did not get enough upvotes in the past. Please create a new issue with a detailed reproducible or feature request if you still face issues.

yury-s avatar Oct 05 '22 23:10 yury-s