我正在使用Watir为web应用程序编写一些测试。我需要从下面的HTML中获取文本'Bishop‘,但不知道如何操作。
<div id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view" style="display: block;">
<div class="workprolabel wpFieldLabel">
<span title="Please select a courtesy title from the list.">Title</span> <span class="validationIndicator wpValidationText"></span>
</div>
<span class="wpFieldViewContent" id="dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5-b45385e5f45b_view_value"><p class="wpFieldValue ">Bishop</p></span>
</div>Firebug告诉我xpath是:
html/body/form/div[5]/div[6]/div[2]/div[2]/div/div/span/span/div[2]/div[4]/div[1]/span[1]/div[2]/span/p/text()但是我不能格式化element_by_xpath来提取它。
发布于 2010-07-15 18:38:28
如果段落是唯一的,您应该能够立即访问该段落:
my_p = browser.p(:class, "wpFieldValue ")
my_text = my_p.text发布于 2010-07-15 18:17:17
试一试
//span[@id='dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5b45385e5f45b_view_value']//text()编辑:
也许这会起作用
path = "//span[@id='dnn_ctr353_Main_ctl00_ctl00_ctl00_ctl07_Field_048b9dfa-bc64-42e4-8bd5b45385e5f45b_view_value']/p";
ie.element_by_xpath(path).text并检查跨度的id是否为常量
发布于 2010-07-15 19:39:27
也许你在名字的末尾有一个额外的空格?
<p class="wpFieldValue ">https://stackoverflow.com/questions/3254446
复制相似问题