【发布时间】:2016-08-30 00:54:42
【问题描述】:
我正在尝试使用 Selenium C# 提取元素后的文本。
我已经找到了 XPath,用于使用 XPath Checker 定位文本。
//*[@id='selectedEciId_5555555']/../following-sibling::text()[1]
在 XPath Checker 中使用上述返回:“5555555 (Customer 5 Name)”。
我已尝试使用以下代码将文本“5555555(客户 5 名称)”提取到使用以下代码行的变量中。
var customer = driver.FindElement(By.XPath("//*@id='selectedEciId_2217611']/../following-sibling::text()[1]")).Text;
但收到一条错误消息,指出“Window.getComputedStyle 的参数 1 未实现接口元素。”
有人可以帮助使用正确的代码来提取文本吗?
HTML 代码复制如下供参考:
<label id="iCheck-txcdyh" for="selectedEciId_1111111" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-txcdyh"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_1111111" value="1111111" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 1111111 (Customer 1 Name)<br>
<label id="iCheck-x44hah" for="selectedEciId_2222222" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-x44hah"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_2222222" value="2222222" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 2222222 (Customer 2 Name)<br>
<label id="iCheck-vljexv" for="selectedEciId_3333333" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-vljexv"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_3333333" value="3333333" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 3333333 (Customer 3 Name)<br>
<label id="iCheck-k4wo8e" for="selectedEciId_4444444" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-k4wo8e"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_4444444" value="4444444" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 4444444 (Customer 4 Name)<br>
<label id="iCheck-zf06hv" for="selectedEciId_5555555" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-zf06hv"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_5555555" value="5555555" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 5555555 (Customer 5 Name)<br>
<label id="iCheck-d9oyt0" for="selectedEciId_6666666" class="ibm-access"></label>
<div aria-disabled="false" aria-checked="false" style="position: relative;" class="iradio_square-blue" role="radio" aria-labelledby="iCheck-d9oyt0"><input style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" name="selectedCompanyId" id="selectedEciId_6666666" value="6666666" type="radio"><ins style="position: absolute; top: -20%; left: -20%; display: block; width: 140%; height: 140%; margin: 0px; padding: 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; border: 0px none; opacity: 0;" class="iCheck-helper"></ins></div> 6666666 (Customer 6 Name)<br>
【问题讨论】: