playwright-java
playwright-java copied to clipboard
[Question] How can I get the text of <td> inside <table>?
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
I've tried to copy the xpath of this
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>
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.
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?
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.