Что нового

Клик по элементу, получить значение элемента в IE

mr.Gbabak

Осваивающий
Сообщения
257
Репутация
23
Добрый день.
Итак, возник вопрос, а возможно ли кликнуть по элементу (ссылка, кнопка) в IE, и потом получить ее URL, name, value и.т.д?
Цель: сделать простейший мультибокс .
 
Автор
M

mr.Gbabak

Осваивающий
Сообщения
257
Репутация
23
Появилась мысль транслировать Url на другие окна, вот таким способом:

Код:
#include <IE.au3>
#include <Array.au3>
#include <File.au3>
#include <UIAutomate.au3>
#include <WinAPIProc.au3>


HotKeySet("{Tab}", "TPause")
HotKeySet("{esc}", "vyx")


Global $Paused, $tUrl, $sUrl





$iPID1 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID1)
$hWnd1 = _WinAPI_EnumProcessWindows($iPID1)
WinWaitActive($hWnd1[1][0])
$oIE1 = _IEAttach($hWnd1[1][0], "hwnd")


$iPID2 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID2)
$hWnd2 = _WinAPI_EnumProcessWindows($iPID2)
WinWaitActive($hWnd2[1][0])
$oIE2 = _IEAttach($hWnd2[1][0], "hwnd")

$iPID3 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID3)

$hWnd3 = _WinAPI_EnumProcessWindows($iPID3)
WinWaitActive($hWnd3[1][0])
$oIE3 = _IEAttach($hWnd3[1][0], "hwnd")



While 1

	$sUrl = _IEPropertyGet($oIE1, "locationurl")
	Sleep(200)

	ConsoleWrite($sUrl & @CRLF)
	If $sUrl <> $tUrl Then

		_IENavigate($oIE2, $sUrl)
		_IENavigate($oIE3, $sUrl)

		$tUrl = $sUrl

	EndIf
WEnd





Func TPause()
	$Paused = Not $Paused
	While $Paused
		Sleep(100)
		ToolTip('Script is "Paused"', 0, 0)
	WEnd
	ToolTip("")
EndFunc   ;==>TPause

Func vyx()
	ToolTip("Good Buy", 0, 0)
	Sleep(1000)
	Exit

EndFunc   ;==>vyx


но, после третьего посещения каких-либо страниц, перестает считываться текущий URL.
Где я не прав?
 
Автор
M

mr.Gbabak

Осваивающий
Сообщения
257
Репутация
23
В общем, идея не понравилась, нашелся более простой способ и эффективный способ через через библиотеку UIAutomate, при обычной навигации работает стабильно

Код:
$oParent = _UIA_GetElementFromHandle($hCtrl1)
$oElement = _UIA_GetControlTypeElement($oParent, "UIA_EditControlTypeId", "Адреса и поиск", 'name', true)
$URL = _UIA_ElementGetPropertyValue($oElement, "ValueValue")

но, изначально данный проект затачивался под мультибоксинг, поэтому необходимо изменять URL на "лету", делая замену сессии.
Код:
While 1

		$oParent = _UIA_GetElementFromHandle($hCtrl1)
		$oElement = _UIA_GetControlTypeElement($oParent, "UIA_EditControlTypeId", "Адреса и поиск", 'name', True)
		$url = _UIA_ElementGetPropertyValue($oElement, "ValueValue")

		If $url <> $tUrl Then

			$rURL1 = StringRegExpReplace($url, $vedushiy, $vedom1)

			$rURL2 = StringRegExpReplace($url, $vedushiy, $vedom2)
			ConsoleWrite($rURL1 & @CRLF)

			WinWaitActive($hWnd2[1][0])
			$oIE2 = _IEAttach($hWnd2[1][0], "hwnd")
			_IENavigate($oIE2, $rURL1, 0)
			If @error Then ConsoleWrite(@error & @CRLF)

			WinWaitActive($hWnd3[1][0])
			$oIE3 = _IEAttach($hWnd3[1][0], "hwnd")
			_IENavigate($oIE3, $rURL2, 0)

			$tUrl = $url

		EndIf
		Sleep(20)
	WEnd

в результате вылетает с ошибкой
Код:
"C:\Program Files (x86)\AutoIt3\Include\IE.au3" (272) : ==> The requested action with this object has failed.:
$oObject.navigate($sUrl)
$oObject^ ERROR


полный код скрипта
Код:
#include <IE.au3>
#include <Array.au3>
#include <File.au3>
#include <UIAutomate.au3>
#include <WinAPIProc.au3>
#include <DDEML.au3>
#include <DDEMLClient.au3>
#include <WinAPI.au3>
#include <MouseOnEvent.au3>

HotKeySet("{Tab}", "TPause")
HotKeySet("{esc}", "vyx")

Global $Paused, $tUrl, $sUrl, $url, $hWnd1, $hWnd, $rURL, $iPID1, $hCtrl1, $hCtrl2, $hCtrl3
Global $vedushiy
Global $vedom1
Global $vedom2
Global $oIE1, $oIE2, $oIE3

; messir23p6054o

; messir1frs0bn92

; messir2t2ta4adj

$iPID1 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID1)
$hWnd1 = _WinAPI_EnumProcessWindows($iPID1)
WinWaitActive($hWnd1[1][0])
$oIE1 = _IEAttach($hWnd1[1][0], "hwnd")

$hCtrl1 = WinGetHandle("[class:IEFrame]", "")

$iPID2 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID2)
$hWnd2 = _WinAPI_EnumProcessWindows($iPID2)
WinWaitActive($hWnd2[1][0])
$oIE2 = _IEAttach($hWnd2[1][0], "hwnd")

$iPID3 = Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private") ; IE10/11 -noframemerging -private
ProcessWait($iPID3)

$hWnd3 = _WinAPI_EnumProcessWindows($iPID3)
WinWaitActive($hWnd3[1][0])
$oIE3 = _IEAttach($hWnd3[1][0], "hwnd")


_IENavigate($oIE1, 'http://amuletdrakona.ru')
_IENavigate($oIE2, 'http://amuletdrakona.ru')
_IENavigate($oIE3, 'http://amuletdrakona.ru')

$vedushiy = InputBox("Вопрос", "Ведущий", "", "", -1, -1, 0, 0)
$vedom1 = InputBox("Вопрос", "Ведомый 1", "", "", -1, -1, 0, 0)
$vedom2 = InputBox("Вопрос", "Ведомый 2", "", "", -1, -1, 0, 0)
TPause()

osnova()

Func osnova()

	While 1

		$oParent = _UIA_GetElementFromHandle($hCtrl1)
		$oElement = _UIA_GetControlTypeElement($oParent, "UIA_EditControlTypeId", "Адреса и поиск с помощью Яндекс", 'name', True)
		$url = _UIA_ElementGetPropertyValue($oElement, "ValueValue")

		If $url <> $tUrl Then

			$rURL1 = StringRegExpReplace($url, $vedushiy, $vedom1)

			$rURL2 = StringRegExpReplace($url, $vedushiy, $vedom2)
			ConsoleWrite($rURL1 & @CRLF)

			WinWaitActive($hWnd2[1][0])
			$oIE2 = _IEAttach($hWnd2[1][0], "hwnd")
			_IENavigate($oIE2, $rURL1, 0)
			If @error Then ConsoleWrite(@error & @CRLF)

			WinWaitActive($hWnd3[1][0])
			$oIE3 = _IEAttach($hWnd3[1][0], "hwnd")
			_IENavigate($oIE3, $rURL2, 0)

			$tUrl = $url

		EndIf
		Sleep(20)
	WEnd

EndFunc   ;==>osnova

Func TPause()
	$Paused = Not $Paused
	While $Paused
		Sleep(100)
		ToolTip('Script is "Paused"', 0, 0)
	WEnd
	ToolTip("")
EndFunc   ;==>TPause

Func vyx()
	ToolTip("Good Buy", 0, 0)
	Sleep(1000)
	Exit

EndFunc   ;==>vyx
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
mr.Gbabak
более простой способ
Узнать текст строки адреса IE
Код:
$sURL = ControlGetText("[class:IEFrame]", "", "Edit1")
ConsoleWrite($sURL & @CRLF)


Осуществить переход, используя строку адреса
Код:
ControlSetText("[class:IEFrame]", "", "Edit1", "autoit-script.ru")
ControlSend("[class:IEFrame]", "", "Edit1", "{enter}")
 
Автор
M

mr.Gbabak

Осваивающий
Сообщения
257
Репутация
23
Как всегда есть еще более простое и элегантное решение.
 

InnI

AutoIT Гуру
Сообщения
4,912
Репутация
1,429
mr.Gbabak
Если я правильно понял
Код:
#include <UIAutomate.au3>

Global $iNum = 3

For $i = 1 To $iNum
  Run("C:\Program Files\Internet Explorer\iexplore.exe -noframemerging -private")
Next

Do
  Sleep(50)
  $aList = WinList("[class:IEFrame]")
Until $aList[0][0] = $iNum

$oMaster = _UIA_GetElementFromHandle($aList[1][1])
_UIA_WaitControlTypeElement($oMaster, "UIA_ButtonControlTypeId", "Обновить (F5)")

GoTo("autoit-script.ru")

$oLink = _UIA_WaitControlTypeElement($oMaster, "UIA_HyperlinkControlTypeId", "Объявления и новости")
$sValue = _UIA_ElementGetPropertyValue($oLink, "Value.Value")
GoTo($sValue)

$oLink = _UIA_WaitControlTypeElement($oMaster, "UIA_HyperlinkControlTypeId", "Список забаненных пользователей")
$sValue = _UIA_ElementGetPropertyValue($oLink, "Value.Value")
GoTo($sValue)

Func GoTo($sUrl)
  For $i = 1 To $iNum
    ControlSetText($aList[$i][1], "", "Edit1", $sUrl)
    ControlSend($aList[$i][1], "", "Edit1", "{enter}")
  Next
  _UIA_WaitControlTypeElement($oMaster, "UIA_ButtonControlTypeId", "Обновить (F5)")
EndFunc
 
Верх