Check if Element with ID has a value

拜拜、爱过 提交于 2020-01-16 13:31:13

问题


How to check if "Some text value" in element p with Id = "SomeID" is there?

<p id="SomeID" class="error" style="display: none"></p>

<p id="SomeID" class="error" style="display: none">Some text value</p>

Here it is in a function form..

function ElementIdText(Web:TembeddedWB; Id:string):string;
var
  node: string;
begin
  if Assigned(Web.Document) and web.DocumentLoaded then begin
  node:=Web.OleObject.Document.GetElementByID(Id).innerText;
  if not VarIsNull(Node) and not VarIsClear(Node) and not AnsiSameStr(node,'') then
  result:=node;
  end;
end;

回答1:


Given

<p id="SomeID" class="error" style="display: none"></p>
<p id="SomeOtherID" class="error" style="display: none">Some text value</p>

To retrieve an attribute, use: 

ShowMessage(WebBrowser1.OleObject.Document.
    GetElementByID('SomeOtherID').getAttribute('style').Display);

will output 'none'.

To get the text of the paragraph you can use this:

ShowMessage(WebBrowser1.OleObject.Document.
    GetElementByID('SomeOtherID').innerText);


来源:https://stackoverflow.com/questions/13442138/check-if-element-with-id-has-a-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!