问题
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