我想提取网页上以table形式编写的文本字符串,但我在return中得到空值

I want to extract a text string on the webpage which is written in the form of table, but I am getting null in return

     WebElement e5 = d1.findElementByXPath("/html/body/div[1]/div[3]/div/div[1]/form/div/div[1]/div/table/tbody/tr[4]/td[2]");
                         String a = e5.getText();
                         System.out.println(a);

_____________________________________________________________________________

我用过getText方法。数据存储在 table 中,所以我使用的策略是首先我想使用 xPath funda 到达该数据的位置,然后我需要提取对应的数据地点。任何人都可以建议一个更好的方法来提前做 so.Thanks。

请在html下面找到:

<div class="wrapper">
<form method="post" action="">
<input id="_csrf" type="hidden" value="psJdnI5AnxjGqT2knrZG" name="_csrf">
<div class="innercontainer">
<div class="leftpanel">
<h2>MY ACCOUNT</h2>
<div>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<tr>
<td>
<strong>Membership ID:</strong>
</td>
<td>2800000101</td>
</tr>
<tr>
<tr>
<tr> </tr>
<tr>
</tbody>
</table>
</div>
</div>
<div class="rightpanel">
</div>
</form>
</div>

html 上面添加的页面。请提出一些替代方案

您需要清理 Xpath,但这应该有所帮助

   WebElement tableText = driver.findElement(By.xpath("yourXpath"));
   String actualText = tableText.getAttribute("textContent");

   System.out.println(actualText)