这是从我们的Web应用程序之一。我想找回价值8把它和值从数据库进行比较。
[FindsBy(How = How.Id, Using = "p_Power Reactors_planned")]
public IWebElement Planned_PR { get; set; }
string PRPlanned = Planned_PR.GetAttribute("p");
HTML:
<p class="big" id="p_Power Reactors_planned">8</p>
我得到空的结果字符串。
由于“8”显示为指定标签的文本,可以通过使用string PRPlanned = Planned_PR.Text
把它拿来
您正在使用错误的命令来检索文本
GetAttribute();
用于检索一个HTML标记的属性的值
例如<p class="big" id="p_Power Reactors_planned">
GetAttribute("class");
- 您将获得价值big
GetAttribute("id");
- 您将获得价值p_Power Reactors_planned
你必须使用.Text
方法来获得所需的文本
e.g string PRPlanned = Planned_PR.Text;
按照HTML的规则,如果下给出标签的元素秋天here那么你可以使用GetAttribute("value");
文本8是<p>
标签的textContext。所以,你需要使用GetAttribute("innerHTML");
方法如下:
[FindsBy(How = How.Id, Using = "p_Power Reactors_planned")]
public IWebElement Planned_PR { get; set; }
string PRPlanned = Planned_PR.GetAttribute("innerHTML");