<?xml version='1.0' encoding="utf-8"?>
      <rss version='2.0'>
      <channel>
      <title>Форум на Исходниках.RU</title>
      <link>https://forum.sources.ru</link>
      <description>Форум на Исходниках.RU</description>
      <generator>Форум на Исходниках.RU</generator>
  	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899425</guid>
        <pubDate>Sun, 28 Jan 2024 21:39:40 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899425</link>
        <description><![CDATA[macomics: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=441696&view=findpost&p=3899424'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Katerina1993 &#064; <time class="tag-quote__quoted-time" datetime="2024-01-28T23:39:51+03:00">28.01.24, 20:39</time></span><div class='quote '>macomics, Inline поддерживается начиная с delphi 2005, а у меня Delphi 7.</div></div><br>
Это не критично, если она будет не inline (просто уберите этот модификатор, я по привычке его использовал). У меня так вообще Lazarus на Linux и адаптировать под Delphi 7 c Internet Explorer бывает сложно.]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899424</guid>
        <pubDate>Sun, 28 Jan 2024 20:39:51 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899424</link>
        <description><![CDATA[Katerina1993: <strong class='tag-b'>macomics</strong>, Inline поддерживается начиная с delphi 2005, а у меня Delphi 7.]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899423</guid>
        <pubDate>Sun, 28 Jan 2024 11:48:38 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899423</link>
        <description><![CDATA[macomics: Еще замечание по поиску элементов по классу. Я этого не делал, но значение className у элемента будет содержать не имя класса, а список классов через разделитель. Необходимо перечислять все классы при поиске или сделать разделение className на соответствующие классы и искать среди них. Как один из вариантов функцию можно организовать так<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;constInvalidHTML = &#39;Invalid HTML document&#39;;</div><div class="code_line">&nbsp;&nbsp;constInvalidHTMLStructure = constInvalidHTML + &#39; structure&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">// Функция поиска элемента на странице с учетом тэга, индекса и имени идентификатора (id) или класса (className)</div><div class="code_line">// aDocument = WebBrowser.Document,</div><div class="code_line">// iNum = номер вхождения элемента в документ с таким ID (начинаются с 1),</div><div class="code_line">// sClassNameOrID = строка с именем класса начинающимся с точки</div><div class="code_line">// &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;или строка с id (не должна начинаться с точки),</div><div class="code_line">// sTagName = имя тэга у элемента</div><div class="code_line">function QueryElement(const aDocument: IDispatch; iNum: LongInt = 1;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const sClassNameOrID: String = &#39;&#39;;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;const sTagName: WideString = &#39;&#39;): IDispatch;</div><div class="code_line">&nbsp;&nbsp;function AnyID(const s1: String; const s2: String): Boolean; begin Result := True; end;</div><div class="code_line">&nbsp;&nbsp;function min(a, b: LongInt): LongInt; inline; begin if a &#60; b then Result := a else Result := b; end;</div><div class="code_line">&nbsp;&nbsp;function PosDef(const aPattern: WideString; const aText: WideString; iDefault: LongInt): LongInt;</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin Result := Pos(aPattern, aText); if Result = 0 then Result := iDefault; end;</div><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;aTabChar: WideString = &#39; &#39;;</div><div class="code_line">&nbsp;&nbsp;aSpaceChar: WideString = #9;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;Body: IHTMLElement2;</div><div class="code_line">&nbsp;&nbsp;Tags: IHTMLElementCollection;</div><div class="code_line">&nbsp;&nbsp;Tag: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;c, i, l, n, Count: LongInt;</div><div class="code_line">&nbsp;&nbsp;f, m: Boolean;</div><div class="code_line">&nbsp;&nbsp;w, s: WideString;</div><div class="code_line">&nbsp;&nbsp;comp: function (const s1: String; const s2: String): Boolean;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;f := False;</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;if iNum &#60; 1 then Exit;</div><div class="code_line">&nbsp;&nbsp;if (sClassNameOrID &#60;&#62; &#39;*&#39;) and (sClassNameOrID &#60;&#62; &#39;&#39;) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;comp := @AnsiSameText;</div><div class="code_line">&nbsp;&nbsp; &nbsp;f := sClassNameOrID[1] = &#39;.&#39;;</div><div class="code_line">&nbsp;&nbsp;end else comp := @AnyID;</div><div class="code_line">&nbsp;&nbsp;if Supports(aDocument, IHTMLDocument2, Doc) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Supports(Doc.body, IHTMLElement2, Body) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if sTagName = &#39;&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;then Tags := Body.getElementByTagName(&#39;*&#39;)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;else Tags := Body.getElementsByTagName(sTagName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Count := Tags.length;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;c := 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;for i := 0 to Count - 1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Tag := Tags.item(i, EmptyParam) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if f then begin // Если ищем по имени класса, тогда надо вручную</div><div class="code_line">// разбить строку className на составляющие и сравнивать имя класса отдельно для каждого класса у элемента</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m := False; // Флаг совпадения одного из классов</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;w := Tag.className; // сохраняем значение в локальную переменную для изменения</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l := Length(w); // можно не буду описывать тривиальные действия</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while l &#62; 0 do begin // цикл достижения конца строки (в строке не осталось имен классов)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inc(l); // можно не буду описывать тривиальные действия</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// нахождение позиции ближайшего к началу строки разделителя имен классов</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n := min(PosDef(aSpaceChar, w, l), PosDef(aTabChar, w, l)); </div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;s := &#39;.&#39; + Copy(w, 1, n - 1); // копирование очередного имени класса в отдельную переменную</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;// пропуск всех символов разделителей между именами (вместо этого можно воспользоваться trim после Delete, но так лучше)</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;while (n &#60; l) and ((w[n] = aSpaceChar) or (w[n] = aTabChar)) do inc(n);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Delete(w, 1, n - 1); // Убираем из строки className очередное имя класса со всеми последующими разделителями</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;l := Length(w); // можно не буду описывать тривиальные действия</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if comp(s, sClassNameOrID) then begin // Сравнение имен классов с именем в параметре</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;m := True; // При совпадении устанавливаем флаг ...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break; // ... и прерываем цикл по именам классов</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if m then inc(c); // Если флаг установлен, тогда совпадение найдено и просто увеличиваем счетчик совпадений</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end else if comp(Tag.id, sClassNameOrID) then inc(c); // тоже самое, но для id</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if c = iNum then begin // Счетчик совпадений равен индексу элемента из параметра</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := Tag; // Возвращаем этот элемент как найденный...</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break; // ... и прерываем цикл по элементам</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end else raise Exception.Create(constInvalidHTMLStructure + &#39;!&#39;);</div><div class="code_line">&nbsp;&nbsp;end else raise Exception.Create(constInvalidHTML + &#39;!&#39;);</div><div class="code_line">end;</div></ol></div></div></div></div><script>preloadCodeButtons('1');</script>Вот как-то так. Но проверьте код. Я опять печатал в браузере. Могут быть очепятки или не исправленные имена переменных. Пройдите по шагам для лучшего представления о происходящем.<br>
Я оставил комментарии в коде. Надеюсь они помогут вам исправить ошибки (особенно проверьте индексы). <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2024-01-28T12:02:19+00:00">28.01.24, 12:02</time></span></span><br>
Ну и примеры поиска элементов с её помощью<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button4Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;Text: WideString;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;title&#39;, 1) as IHTMLElement; // Поиск первого среди всех на странице по id</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;.submitbutton&#39;, 1) as IHTMLElement; // Поиск первого среди всех на странице по className</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;title&#39;, 5) as IHTMLElement; // Поиск пятого элемента среди всех на странице по id и индексу</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;.submitbutton&#39;, 3) as IHTMLElement; // Поиск третьего элемента по className и индексу</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;title&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди input по id</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;.submitbutton&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди input по className</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;title&#39;, 2, &#39;input&#39;) as IHTMLElement; // Поиск второго элемента только среди input по id и индексу</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;.submitbutton&#39;, 4, &#39;input&#39;) as IHTMLElement; // Поиск четвертого элемента только среди input по className и индексу</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;&#39;) as IHTMLElement; // Поиск первого элемента на странице по индексу (неявно)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;*&#39;, 1) as IHTMLElement; // Поиск первого элемента на странице по индексу (явно)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;&#39;, 3, &#39;*&#39;) as IHTMLElement; // Поиск третьего элемента на странице по индексу (явно и с указанием маски тэгов)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := QueryElement(WebBrowser1.Document, &#39;*&#39;, 4, &#39;input&#39;) as IHTMLElement; // Поиск четвертого элемента только среди input по индексу</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899421</guid>
        <pubDate>Sun, 28 Jan 2024 05:09:54 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899421</link>
        <description><![CDATA[macomics: Тогда зачем вам там переменная Caption?<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button4Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;Text: WideString;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;title&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди ссылок</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899420</guid>
        <pubDate>Sat, 27 Jan 2024 23:08:02 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899420</link>
        <description><![CDATA[Katerina1993: В процедуре вызываю:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button4Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;Text: OleVariant;</div><div class="code_line">&nbsp;&nbsp;Caption : WideString;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;title&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди ссылок</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899419</guid>
        <pubDate>Sat, 27 Jan 2024 21:52:59 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899419</link>
        <description><![CDATA[macomics: Так где вы это вызываете. Если вне метода основного окна программы, тогда используйте Form1.Caption]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899418</guid>
        <pubDate>Sat, 27 Jan 2024 21:28:44 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899418</link>
        <description><![CDATA[Katerina1993: Ошибку выдает, на строке где Caption.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;Text: OleVariant;</div><div class="code_line">&nbsp;&nbsp;Caption : WideString;</div><div class="code_line">&nbsp;</div><div class="code_line">.....</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;Caption := WideCharToString(@Text[1]);</div></ol></div></div></div></div><br>
<br>
<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>[Error] Unit1.pas(232): Variable required</div></div>]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899416</guid>
        <pubDate>Sat, 27 Jan 2024 17:18:15 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899416</link>
        <description><![CDATA[macomics: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=441696&view=findpost&p=3899415'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Katerina1993 &#064; <time class="tag-quote__quoted-time" datetime="2024-01-27T17:11:01+00:00">27.01.24, 17:11</time></span><div class='quote '>Работает, только первые две строчки не пойму для чего getAttribute и WideCharToString? Мне удалось запусить только через Elem.setAttribute.</div></div><br>
Первые две строчки это получение. Необходима дополнительная переменная типа WideString перед преобразованием кодировок. Свойство Caption у формы требует для установки строку в кодировке ANSI, а из интерфейса будет получен OleVariant. Присвоение его к строке нужного типа автоматически преобразует данные в строку WideString. А вот дальше из WideString надо руками преобразовать текст в ANSI путем вызова WideCharToString. Но в качестве параметра этой функции нужна строка типа PWideChar. Преобразовать сразу из OleVariant в PWideChar не так просто. Гораздо проще использовать дополнительную переменную, которая уже будет содержать исходные данные для перекодировки в ANSI. И уже в заголовке формы строка будет отображена в правильной кодировке символов.<br>
<br>
И третья строка изменяет значение свойства value на &#39;Send text&#33;&#39;. Но помните, что там тоже используются не String, а WideString и требуется соблюдать и преобразовывать кодировку текста.]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899415</guid>
        <pubDate>Sat, 27 Jan 2024 17:11:01 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899415</link>
        <description><![CDATA[Katerina1993: Работает, только первые две строчки не пойму для чего getAttribute и WideCharToString? Мне удалось запусить только через Elem.setAttribute.]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899414</guid>
        <pubDate>Sat, 27 Jan 2024 16:35:49 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899414</link>
        <description><![CDATA[macomics: Значит оно доступно не напрямую, а через getAttribute/setAttribute<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Text := Elem.getAttribute(&#39;value&#39;, 0);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Caption := WideCharToString(@Text[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Elem.setAttribute(&#39;value&#39;, &#39;Send text!&#39;, 0);</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899413</guid>
        <pubDate>Sat, 27 Jan 2024 16:26:32 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899413</link>
        <description><![CDATA[Katerina1993: <div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>Текст для input задается не как innerText или innerHTML, а в поле value&#33;</div></div><br>
У меня почему-то выдает сообщение об ошибке.<br>
<br>
<span class="b-attach" data-size="24121" data-hits="107" data-attach-id="65397" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=65397' title='Скачать файл' target='_blank'>Err1.png</a> (, : 107)
		</span>]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899412</guid>
        <pubDate>Sat, 27 Jan 2024 15:43:45 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899412</link>
        <description><![CDATA[macomics: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=441696&view=findpost&p=3899411'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Katerina1993 &#064; <time class="tag-quote__quoted-time" datetime="2024-01-27T14:36:37+00:00">27.01.24, 14:36</time></span><div class='quote '>Еще интерсно как можно на одну кнопку button4 повесить и заполнение полей и отправку?</div></div><br>
Смотря какую кнопку вы имеете ввиду. Если кнопку на странице, тогда просто измените её тип с submit на button и добавьте обработчик onClick. На JavaScript в обработчике нажатия добавляете заполнение полей формы, а в конце вызываете submit для формы<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">function clickOnButton(e) {</div><div class="code_line">&nbsp;&nbsp;const f = e.target.form; // Получаем форму, на которой находится кнопка</div><div class="code_line">&nbsp;&nbsp;e.preventDefault(); // Прерываем цепочку передачи сообщений к нижерасположенным элементам</div><div class="code_line">&nbsp;&nbsp;f.title.value = &quot;Hello world&quot;; // Заполняем поля формы (заголовок)</div><div class="code_line">&nbsp;&nbsp;f.textbox.innerText = &quot;Autofilled by click!&quot;; // и текстовое поле тоже (не забудьте у textarea добавить name=&quot;textbox&quot;)</div><div class="code_line">&nbsp;&nbsp;f.submit(); // Отправка формы</div><div class="code_line">}</div><div class="code_line">const formButton = document.querySelector(&quot;.submitButton&quot;);</div><div class="code_line">if (formButton) {</div><div class="code_line">&nbsp;&nbsp;formButton.addEventListener(&quot;click&quot;, clickOnButton);</div><div class="code_line">}</div></ol></div></div></div></div><br>
<br>
Если надо заполнить поля формы перед отправкой при нажатии на кнопке Delphi, тогда придется найти каждое поле формы отдельно и установить его соответствующие атрибуты.<br>
<br>
Если вы хотите, чтобы я вам заполнил поля на форме Delphi для найденного элемента, тогда это будет так (не забудьте выключить таймер)<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button3Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 1, &#39;test&#39;, &#39;a&#39;) as IHTMLElement; // Поиск первой только среди ссылок с id=&quot;test&quot; (по тэгу и id)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;edElementTag.Text := WideCharToString(@Elem.tagName[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;edElementId.Text := WideCharToString(@Elem.id[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;edElementinnerHTML.Text := WideCharToString(@Elem.innerHTML[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;edElementclassName.Text := WideCharToString(@Elem.className[1]);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;edElementinnerText.Text := WideCharToString(@Elem.innerText[1]);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Elem.click; // Кликнуть по ссылке (выполнить OnClick или переход по href)</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div> Если же надо выполнять поиск по названию класса, тогда можно написать похожую функцию<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;constInvalidHTML = &#39;Invalid HTML document&#39;;</div><div class="code_line">&nbsp;&nbsp;constInvalidHTMLStructure = constInvalidHTML + &#39; structure&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">// aDocument = WebBrowser.Document, iNum = номер вхождения элемента в документ с таким ID (начинаются с 1), sClassName = строка ID, sTagName = имя тэга у элемента</div><div class="code_line">function GetElementByIndexClassNameAndTagName(const aDocument: IDispatch; iNum: LongInt = 1; const sClassName: String = &#39;*&#39;; const sTagName: WideString = &#39;*&#39;): IDispatch;</div><div class="code_line">&nbsp;&nbsp;function AnyID(const s1: String; const s2: String): Boolean; begin Result := True; end;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;Body: IHTMLElement2;</div><div class="code_line">&nbsp;&nbsp;Tags: IHTMLElementCollection;</div><div class="code_line">&nbsp;&nbsp;Tag: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;i, c, Count: LongInt;</div><div class="code_line">&nbsp;&nbsp;comp: function (const s1: String; const s2: String): Boolean;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;if iNum &#60; 1 then Exit;</div><div class="code_line">&nbsp;&nbsp;if (sClassName &#60;&#62; &#39;*&#39;) and (sClassName &#60;&#62; &#39;&#39;) then comp := @AnsiSameText else comp := @AnyID;</div><div class="code_line">&nbsp;&nbsp;if Supports(aDocument, IHTMLDocument2, Doc) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Supports(Doc.body, IHTMLElement2, Body) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Tags := Body.getElementsByTagName(sTagName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Count := Tags.length;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;c := 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;for i := 0 to Count - 1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Tag := Tags.item(i, EmptyParam) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if comp(Tag.className, sClassName) then inc(c);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if c = iNum then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := Tag;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end else raise Exception.Create(constInvalidHTMLStructure + &#39;!&#39;);</div><div class="code_line">&nbsp;&nbsp;end else raise Exception.Create(constInvalidHTML + &#39;!&#39;);</div><div class="code_line">end;</div></ol></div></div></div></div> <br>
<br>
<span class="tag-color tag-color-named" data-value="mergepost" style="color: mergepost"><span class='tag-size' data-value='7' style='font-size:7pt;'>Добавлено <time class="tag-mergetime" datetime="2024-01-27T15:50:11+00:00">27.01.24, 15:50</time></span></span><br>
И еще<div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=441696&view=findpost&p=3899411'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Katerina1993 &#064; <time class="tag-quote__quoted-time" datetime="2024-01-27T14:36:37+00:00">27.01.24, 14:36</time></span><div class='quote '>Сделала заполнение полей.<br>
<br>
procedure TForm1.Button4Click(Sender: TObject);<br>
var<br>
  Elem: IHTMLElement;<br>
begin<br>
  try<br>
 <br>
    Elem := GetElementById(WebBrowser1.Document, &#39;title&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди ссылок<br>
    if Assigned(Elem) then begin<br>
       Elem.innerText:=&#39;Название&#39;;<br>
 <br>
    end;<br>
    Elem := GetElementById(WebBrowser1.Document, &#39;message&#39;, 1, &#39;textarea&#39;) as IHTMLElement; // Поиск только среди ссылок<br>
    if Assigned(Elem) then begin<br>
        Elem.innerHTML:=&#39;Тестовое описание&#39;<br>
    end;<br>
  except<br>
 <br>
  end;<br>
end;<br>
<br>
А вот в кнопке у меня только класс прописан, пример на картинке.</div></div><br>
Текст для input задается не как innerText или innerHTML, а в поле value&#33;<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">Elem.value := &#39;Отправить сообщение&#39;;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899411</guid>
        <pubDate>Sat, 27 Jan 2024 14:36:37 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899411</link>
        <description><![CDATA[Katerina1993: <strong class='tag-b'>macomics</strong>, в 8 посту несколько примеров, как искать по блоку, id и по индексу, а как по классу.<br>
<br>
Сделала заполнение полей.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button4Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;title&#39;, 1, &#39;input&#39;) as IHTMLElement; // Поиск только среди ссылок</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; Elem.innerText:=&#39;Название&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;message&#39;, 1, &#39;textarea&#39;) as IHTMLElement; // Поиск только среди ссылок</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Elem.innerHTML:=&#39;Тестовое описание&#39;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div><br>
А вот в кнопке у меня только класс прописан, пример на картинке.<br>
<span class="b-attach" data-size="35343" data-hits="93" data-attach-id="65396" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=65396' title='Скачать файл' target='_blank'>img1.jpg</a> (, : 93)
		</span><br>
Еще интерсно как можно на одну кнопку button4 повесить и заполнение полей и отправку?]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899410</guid>
        <pubDate>Sat, 27 Jan 2024 11:10:22 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899410</link>
        <description><![CDATA[macomics: Например<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">procedure TForm1.Button3Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 1, &#39;test&#39;, &#39;a&#39;) as IHTMLElement; // Поиск первой только среди ссылок с id=&quot;test&quot; (по тэгу и id)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Elem.click; // Кликнуть по ссылке (выполнить OnClick или переход по href)</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899408</guid>
        <pubDate>Sat, 27 Jan 2024 10:29:25 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899408</link>
        <description><![CDATA[Katerina1993: Комментарий в условие <br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '><br>
// Делаем с элементом что хотим<br>
</div></div><br>
Все таки, что нужно сделать, чтобы был переход по ссылке и открылась форма?]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899407</guid>
        <pubDate>Sat, 27 Jan 2024 09:59:54 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899407</link>
        <description><![CDATA[macomics: Да. У вас в примере туда надо передать &#39;test&#39;. Можно так же модифицировать код для поиска элементов без атрибута id.<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;constInvalidHTML = &#39;Invalid HTML document&#39;;</div><div class="code_line">&nbsp;&nbsp;constInvalidHTMLStructure = constInvalidHTML + &#39; structure&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">// aDocument = WebBrowser.Document, ID = строка ID, iNum = номер вхождения элемента в документ с таким ID (начинаются с 1)</div><div class="code_line">function GetElementByIndexIdAndTagName(const aDocument: IDispatch; iNum: LongInt = 1; const sID: String = &#39;*&#39;; const sTagName: WideString = &#39;*&#39;): IDispatch;</div><div class="code_line">&nbsp;&nbsp;function AnyID(const s1: String; const s2: String): Boolean; begin Result := True; end;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;Body: IHTMLElement2;</div><div class="code_line">&nbsp;&nbsp;Tags: IHTMLElementCollection;</div><div class="code_line">&nbsp;&nbsp;Tag: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;i, c, Count: LongInt;</div><div class="code_line">&nbsp;&nbsp;comp: function (const s1: String; const s2: String): Boolean;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;if iNum &#60; 1 then Exit;</div><div class="code_line">&nbsp;&nbsp;if (sID &#60;&#62; &#39;*&#39;) and (sID &#60;&#62; &#39;&#39;) then comp := @AnsiSameText else comp := @AnyID;</div><div class="code_line">&nbsp;&nbsp;if Supports(aDocument, IHTMLDocument2, Doc) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Supports(Doc.body, IHTMLElement2, Body) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Tags := Body.getElementsByTagName(sTagName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Count := Tags.length;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;c := 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;for i := 0 to Count - 1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Tag := Tags.item(i, EmptyParam) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if comp(Tag.id, sID) then inc(c);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if c = iNum then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := Tag;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end else raise Exception.Create(constInvalidHTMLStructure + &#39;!&#39;);</div><div class="code_line">&nbsp;&nbsp;end else raise Exception.Create(constInvalidHTML + &#39;!&#39;);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Button3Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 1, &#39;test&#39;, &#39;a&#39;) as IHTMLElement; // Поиск первой только среди ссылок с id=&quot;test&quot; (по тэгу и id)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 10) as IHTMLElement; // Поиск по индексу десятого элемента в документе (только по индексу)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 2, &#39;myid&#39;) as IHTMLElement; // Поиск второго элемента с id=&quot;myid&quot; (по индексу и id)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementByIndexIdAndTagName(WebBrowser1.Document, 3, &#39;&#39;, &#39;div&#39;) as IHTMLElement; // Поиск третьего блочного элемента (&#60;div&#62;...&#60;/div&#62;) (по индексу и тэге)</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899405</guid>
        <pubDate>Sat, 27 Jan 2024 08:30:15 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899405</link>
        <description><![CDATA[Katerina1993: Вот в этой строке:<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">Elem := GetElementById(WebBrowser1.Document, &#39;element_id&#39;, 1, &#39;a&#39;) as IHTMLElement;</div></ol></div></div></div></div><br>
Вместо element_id нужно использовать значения атрибута ссылки? У меня например test.]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899402</guid>
        <pubDate>Fri, 26 Jan 2024 22:42:06 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899402</link>
        <description><![CDATA[macomics: Вот так всегда, когда набираешь код в браузере по памяти и не проверяешь.<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;constInvalidHTML = &#39;Invalid HTML document&#39;;</div><div class="code_line">&nbsp;&nbsp;constInvalidHTMLStructure = constInvalidHTML + &#39; structure&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">// aDocument = WebBrowser.Document, ID = строка ID, iNum = номер вхождения элемента в документ с таким ID (начинаются с 1)</div><div class="code_line">function GetElementById(const aDocument: IDispatch; const ID: String; iNum: LongInt = 1; const tagName: WideString = &#39;*&#39;): IDispatch;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;Body: IHTMLElement2;</div><div class="code_line">&nbsp;&nbsp;Tags: IHTMLElementCollection;</div><div class="code_line">&nbsp;&nbsp;Tag: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;i, c, Count: LongInt;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;if iNum &#60; 1 then Exit;</div><div class="code_line">&nbsp;&nbsp;if Supports(aDocument, IHTMLDocument2, Doc) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Supports(Doc.body, IHTMLElement2, Body) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Tags := Body.getElementsByTagName(tagName);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Count := Tags.length;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;c := 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;for i := 0 to Count - 1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Tag := Tags.item(i, EmptyParam) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if AnsiSameText(Tag.id, ID) then inc(c);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if c = iNum then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := Tag;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end else raise Exception.Create(constInvalidHTMLStructure + &#39;!&#39;);</div><div class="code_line">&nbsp;&nbsp;end else raise Exception.Create(constInvalidHTML + &#39;!&#39;);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Button3Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;element_id&#39;, 1, &#39;a&#39;) as IHTMLElement; // Поиск только среди ссылок</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>Вот исправленный. Я вместо Doc.body передавал Doc и не поправил GUID интерфейса после копирования.]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899401</guid>
        <pubDate>Fri, 26 Jan 2024 21:43:47 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899401</link>
        <description><![CDATA[Katerina1993: Просто у меня появляется ошибка, когда я открываю веб-страницу и при нажатии кнопки, где активируется элемент в dom. Пример:<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '>Access violation at adress 43CFCDAA in module &#39;mshtml.dll&#39;</div></div><br>
Вот скриншот ошибки.<br>
<span class="b-attach" data-size="115441" data-hits="91" data-attach-id="65392" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=65392' title='Скачать файл' target='_blank'>Screenshot_1.jpg</a> (, : 91)
		</span><br>
Когда я нажимаю OK выделяется эта строка, я решила что с ней что-то не так и нужно в скобках изменить параметр.<br>
<span class="b-attach" data-size="101997" data-hits="99" data-attach-id="65393" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=65393' title='Скачать файл' target='_blank'>Screenshot_2.jpg</a> (, : 99)
		</span>]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899400</guid>
        <pubDate>Fri, 26 Jan 2024 19:35:52 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899400</link>
        <description><![CDATA[macomics: <div class='tag-quote'><a class='tag-quote-link' href='https://forum.sources.ru/index.php?showtopic=441696&view=findpost&p=3899399'><span class='tag-quote-prefix'>Цитата</span></a> <span class='tag-quote__quote-info'>Katerina1993 &#064; <time class="tag-quote__quoted-time" datetime="2024-01-26T19:23:36+00:00">26.01.24, 19:23</time></span><div class='quote '>А вот здесь, что указываем. Вместо звездочки.</div></div><br>
Ничего. Используйте как есть. &#39;*&#39; получает все тэги из body в document. Или можете передать её через параметры и тогда можно будет искать не просто по id но еще и конкретный тэг (например, только ссылки, указав там &#39;a&#39; или только блочные тэги, указав &#39;div&#39;).]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899399</guid>
        <pubDate>Fri, 26 Jan 2024 19:23:36 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899399</link>
        <description><![CDATA[Katerina1993: А вот здесь, что указываем. Вместо звездочки.<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">Tags := Body.getElementsByTagName(&#39;*&#39;);</div></ol></div></div></div></div>]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899395</guid>
        <pubDate>Fri, 26 Jan 2024 17:55:33 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899395</link>
        <description><![CDATA[macomics: Вам это нужно?<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">const</div><div class="code_line">&nbsp;&nbsp;constInvalidHTML = &#39;Invalid HTML document&#39;;</div><div class="code_line">&nbsp;&nbsp;constInvalidHTMLStructure = constInvalidHTML + &#39; structure&#39;;</div><div class="code_line">&nbsp;</div><div class="code_line">// aDocument = WebBrowser.Document, ID = строка ID, iNum = номер вхождения элемента в документ с таким ID (начинаются с 1)</div><div class="code_line">function GetElementById(const aDocument: IDispatch; const ID: String; iNum: LongInt): IDispatch;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;Body: IHTMLElement2;</div><div class="code_line">&nbsp;&nbsp;Tags: IHTMLElementCollection;</div><div class="code_line">&nbsp;&nbsp;Tag: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;i, c, Count: LongInt;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;if iNum &#60; 1 then Exit;</div><div class="code_line">&nbsp;&nbsp;if Supports(aDocument, IHTMLDocument2, Doc) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Supports(Doc.body, IHTMLElement2, Body) then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Tags := Body.getElementsByTagName(&#39;*&#39;);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;Count := Tags.length;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;c := 0;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;for i := 0 to Count - 1 do begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Tag := Tags.item(i, EmptyParam) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if AnsiSameText(Tag.id, ID) then inc(c);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if c = iNum then begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Result := Tag;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end else raise Exception.Create(constInvalidHTMLStructure + &#39;!&#39;);</div><div class="code_line">&nbsp;&nbsp;end else raise Exception.Create(constInvalidHTML + &#39;!&#39;);</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Button3Click(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Elem: IHTMLElement;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;try</div><div class="code_line">&nbsp;&nbsp; &nbsp;Elem := GetElementById(WebBrowser1.Document, &#39;myid&#39;, 1) as IHTMLElement;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(Elem) then begin</div><div class="code_line">// Делаем с элементом что хотим</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;except</div><div class="code_line">// Ошибки поиска элементов</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div></ol></div></div></div></div>]]></description>
        <author>macomics</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      <item>
        <guid isPermaLink='true'>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899393</guid>
        <pubDate>Fri, 26 Jan 2024 16:46:57 +0000</pubDate>
        <title>Как сделать автоматическое нажатье по ссылке в окне браузера?</title>
        <link>https://forum.sources.ru/index.php?showtopic=441696&amp;view=findpost&amp;p=3899393</link>
        <description><![CDATA[Katerina1993: Написала программу для открытия страниц браузера. В боковой панели сделала вывод информации о dom-элементах. Чтобы открыть ссылку нужно по ней щелкнуть. Если навести мышкой и посмотреть в панели то атрибут id равняется test. Gif пример работы программы ниже.<br>
<img class='tag-img' src='https://i.ibb.co/q0VTH8X/Browser-Delphi.gif' alt='user posted image'><br>
Подскажите можно как-нибудь по id найти в документе html и заставить нажать по ссылке автоматически.<br>
<br>
В своей программе я подключаю дополнительные файлы.<br>
<div class='tag-quote'><span class='tag-quote-prefix'>Цитата</span> <div class='quote '><br>
WBFuncs – для процедуры WB_Navigate.<br>
MSHTML – для интерфейса IHTMLElement.<br>
</div></div><br>
<br>
Для работы использую компонент WebBrowser.<br>
<br>
Код полностью (исходники: <span class="b-attach" data-size="72303" data-hits="15" data-attach-id="65391" data-attach-post-id="0">
			<span class="b-attach__title"></span><a class='b-attach-link' href='https://forum.sources.ru/index.php?act=Attach&amp;type=post&amp;id=0&amp;attach_id=65391' title='Скачать файл' target='_blank'>ExampleSource.zip</a> (, : 15)
		</span>)<br>
<br>
<div class='tag-code'><span class='pre_code'></span><div class='code  code_collapsed ' title='Подсветка синтаксиса доступна зарегистрированным участникам Форума.' style=''><div><div><ol type="1"><div class="code_line">unit Unit1;</div><div class="code_line">&nbsp;</div><div class="code_line">interface</div><div class="code_line">&nbsp;</div><div class="code_line">uses</div><div class="code_line">&nbsp;&nbsp;Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,</div><div class="code_line">&nbsp;&nbsp;Dialogs, StdCtrls, OleCtrls, SHDocVw, ComCtrls, ExtCtrls, WBFuncs;</div><div class="code_line">&nbsp;</div><div class="code_line">type</div><div class="code_line">&nbsp;&nbsp;TForm1 = class(TForm)</div><div class="code_line">&nbsp;&nbsp; &nbsp;WebBrowser1: TWebBrowser;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Button1: TButton;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PageControl: TPageControl;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel1: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TabSheet1: TTabSheet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TabSheet2: TTabSheet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PageControl1: TPageControl;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TabSheet3: TTabSheet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TabSheet4: TTabSheet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;TabSheet5: TTabSheet;</div><div class="code_line">&nbsp;&nbsp; &nbsp;GroupBox1: TGroupBox;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edSearchAndHighlight: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Button2: TButton;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PnlElementInfo1: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;PnlHandle: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementTag: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label1: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel3: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementId: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label2: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel4: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementinnerHTML: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label3: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Timer1: TTimer;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel5: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementclassName: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label4: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel6: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementinnerText: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label5: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Panel7: TPanel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;edElementhref: TEdit;</div><div class="code_line">&nbsp;&nbsp; &nbsp;Label6: TLabel;</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure Button1Click(Sender: TObject);</div><div class="code_line">&nbsp;&nbsp; &nbsp;procedure Timer1Timer(Sender: TObject);</div><div class="code_line">&nbsp;&nbsp;private</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Private declarations }</div><div class="code_line">&nbsp;&nbsp; &nbsp;FPrevBrowser: TWebbrowser;</div><div class="code_line">&nbsp;&nbsp;public</div><div class="code_line">&nbsp;&nbsp; &nbsp;{ Public declarations }</div><div class="code_line">&nbsp;&nbsp; &nbsp;function GetCurrentWB: TWebbrowser;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;Form1: TForm1;</div><div class="code_line">&nbsp;</div><div class="code_line">implementation</div><div class="code_line">&nbsp;</div><div class="code_line">uses</div><div class="code_line">&nbsp;&nbsp;MSHTML;</div><div class="code_line">&nbsp;</div><div class="code_line">{$R *.dfm}</div><div class="code_line">&nbsp;</div><div class="code_line">function TForm1.GetCurrentWB: TWebbrowser;</div><div class="code_line">begin</div><div class="code_line">&nbsp;&nbsp;Result := nil;</div><div class="code_line">&nbsp;&nbsp;with PageControl do</div><div class="code_line">&nbsp;&nbsp; &nbsp;if ActivePage.ControlCount &#62; 0 then</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;if ActivePage.Controls[0] is TWebbrowser then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Result := (TWebbrowser(ActivePage.Controls[0]));</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp;end else</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;Result := FPrevBrowser;</div><div class="code_line">&nbsp;&nbsp; &nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Button1Click(Sender: TObject);</div><div class="code_line">begin</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;WB_Navigate(GetCurrentWB, &#39;http://mysite1.su&#39;);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;WB_SetFocus(GetCurrentWB);</div><div class="code_line">&nbsp;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">procedure TForm1.Timer1Timer(Sender: TObject);</div><div class="code_line">var</div><div class="code_line">&nbsp;&nbsp;MausPos: TPoint;</div><div class="code_line">&nbsp;&nbsp;Element: IHTMLElement;</div><div class="code_line">&nbsp;&nbsp;imgElement: IHTMLIMGElement;</div><div class="code_line">&nbsp;&nbsp;scrElement: IHTMLLinkElement;</div><div class="code_line">&nbsp;&nbsp;x, y: Integer;</div><div class="code_line">&nbsp;&nbsp;Doc: IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp;CurrentWB: TWebbrowser;</div><div class="code_line">begin</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp;CurrentWB := GetCurrentWB;</div><div class="code_line">&nbsp;&nbsp; &nbsp;if Assigned(CurrentWB) then</div><div class="code_line">&nbsp;&nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; Doc := CurrentWB.Document as IHTMLDocument2;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;if Assigned(doc) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;GetCursorPos(MausPos);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;mauspos := CurrentWB.ScreenToClient(mauspos);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;x := MausPos.x;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;y := MausPos.y;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Element := GetElementAtPos(doc, x, y);</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if Assigned(Element) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;begin</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edElementTag.Text := Element.tagName;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edElementId.Text := Element.id;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edElementinnerHTML.Text := Element.innerHTML;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edElementclassName.Text := Element.className;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; edElementinnerText.Text := Element.innerText;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Element.QueryInterface(IHTMLIMGElement, imgElement);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if assigned(imgElement) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;edElementhref.Text := imgElement.href;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Element.QueryInterface(IHTMLLinkElement, scrElement);</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if assigned(scrElement) then</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;edElementhref.Text := scrElement.href;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;end;</div><div class="code_line">&nbsp;&nbsp;</div><div class="code_line">&nbsp;</div><div class="code_line">&nbsp;&nbsp;end;</div><div class="code_line">end;</div><div class="code_line">&nbsp;</div><div class="code_line">end.</div></ol></div></div></div></div><br>
<br>
Исходники приложила. Там сама программа и сайт который я использую для тестирования.]]></description>
        <author>Katerina1993</author>
        <category>Delphi: Общие вопросы</category>
      </item>
	
      </channel>
      </rss>
	