How to get text from table cell

时间:2016-07-28 20:21:25

标签: javascript html selenium selenium-webdriver

I have to get the text 2010 manstreet san Jose ca from the HTML below. I have tried using XPath contains. It doesn't work.--------------------------------------------------------------------------------------------------------------------

HTML:

<input id="St" type="hidden" value="1" name="St"/>
<div>
<div style="text-align:right;width:428px;">
<style> .myStyle { border: 1px solid silver;  background-color: #F9E0E0; } </style>
<input id="hd" type="hidden" value="" name="hD"/>

<input id="Deleting" type="hidden" value="" name="D"/>
<h3>somthing</h3>
<br/>
<table width="100%" cellspacing="0" cellpadding="3" border="0">
<thead>
<tbody>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<tr>
<td>
2010 manstreet 
<br/>
san jose CA 95124
</td>
<td>
</tr>
<tr>
<tr>
<tr>
<tr>
<tr>

2 个答案:

答案 0 :(得分:0)

我认为您应该在.中使用text()代替xpath,如下所示: -

//tr/td[contains(., '2010 manstreet')] 

希望它有效......:)

答案 1 :(得分:0)

通过查找您想要获取的文本来查找元素不是一个好方法,因为它可能会因另一个案例而发生变化。相反,您可以通过"table > tbody"获取元素,请检查以下python控制台:

>>> print driver.find_element_by_css_selector("table > tbody").text
2010 manstreet
san jose CA 95124