我是 selenium 的新手,一直(PYTHON)
卡在某一点上,需要专家的帮助。我的html是这样的:
<div id='d3_tree'>
<svg>
<g transform="translate(20,50)>
<g class='node'>
<foreignobject></foreignobject>
<original_title>
<table>
<tbody>
<tr>
<td>t1key1</td>
<td>t1val1</td>
</tr>
<tr>
<td>t1key2</td>
<td>t1val2</td>
</tr>
<tr>
<td>t1key3</td>
<td>t1val3</td>
</tr>
</tbody>
</table>
</original_title>
</g>
<g class='node pe_node'>
<foreignobject></foreignobject>
<original_title>
<table>
<tbody>
<tr>
<td>t2key1</td>
<td>t2val1</td>
</tr>
<tr>
<td>t2key2</td>
<td>t2val2</td>
</tr>
<tr>
<td>t2key3</td>
<td>t2val3</td>
</tr>
</tbody>
</table>
</original_title>
</g>
<g class='node pe_node'>
<foreignobject></foreignobject>
<original_title>
<table>
<tbody>
<tr>
<td>t3key1</td>
<td>t3val1</td>
</tr>
<tr>
<td>t3key2</td>
<td>t3val2</td>
</tr>
<tr>
<td>t3key3</td>
<td>t3val3</td>
</tr>
</tbody>
</table>
</original_title>
</g>
</g>
</svg>
</div>
我需要的是具有类 node.pe_node 的所有元素,并且在每个 node.pe 节点元素内我需要表格第三行第二列的文本。(t2val3 t3val3)
我能够获得具有类 node.pe_node 的元素
pe_nodes = self.driver.find_elements_by_css_selector(".node.vm.node_pe")
现在我正在遍历 pe_nodes 以获取第三列的值
for node in pe_nodes:
petext = node.find_element(By.XPATH, "//tr[3]/td[2]").text //not working
petext = node.find_element(By.XPATH, "//tr[3]/td[2]").get_text() //not working
谁能指导我如何获得所需的文本?有没有办法引用每个节点元素内的表列?