Задать вопрос
@IvanSstarr

Сравнение объектов Powershell+Selenium+Chrome и Powershell+IE, почему такая огромная разница?

При работе Powershell+Selenium+Chrome и Powershell+IE столкнулся с проблемой что Powershell+Selenium не показывает все атрибуты объекта, а выдает только по одному, покажу на примере.

Powershell+Selenium+Chrome, выполняю код:
$Driver = New-Object -TypeName "OpenQA.Selenium.Chrome.ChromeDriver" #Запускаю Chrome
$Driver.Navigate().GoToUrl("https://www.yandex.ru") #Переходим на www.yandex.ru
$Driver.FindElementsByClassName("button")[1] #Получаю свойства объекта кнопка "найти" на странице yandex.ru

5c614ba6bcc33864346541.jpeg

Далее, выполняю
$Driver.FindElementsByClassName("button")[1].GetProperty("textContent") #Получаю текстовое значение кнопки
5c614be838e2b877073325.jpeg

А как получить все атрибуты сразу а не по одному?

Теперь Powershell+IE, выполняем
$ie = New-Object -ComObject InternetExplorer.Application #Создаем новый объект IE
$ie.Navigate("https://www.yandex.ru") #Переходим на www.yandex.ru
$ie.Visible = $true #Делаем браузер видимым
Start-Sleep -Seconds 2 #Ждем 2 секунды что бы страница загрузилась
$ie.Document.getElementsByClassName("button")[1] #Получаю свойства объекта кнопка "найти" на странице yandex.ru

5c614c3915dd2195716598.png

Тут IE показывает все атрибуты сразу, как добиться того же от Powershell+Selenium+Chrome?
Сразу говорю что использовать Powershell+IE из за ряда причин не могу, нужен Powershell+Selenium+Chrome

P.S. Написал функцию (костыль), проблема решена)

function get-all-attribute-web-SE-elements($web_element){
$attributs = "className","id","tagName","parentElement","style","onhelp","onclick","ondblclick","onkeydown","onkeyup","onkeypress","onmouseout","onmouseover","onmousemove","onmousedown","onmouseup","document","title","language","onselectstart","sourceIndex","recordNumber","lang","offsetLeft","offsetTop","offsetWidth","offsetHeight","offsetParent","innerHTML","innerText","outerHTML","outerText","parentTextEdit","isTextEdit","filters","ondragstart","onbeforeupdate","onafterupdate","onerrorupdate","onrowexit","onrowenter","ondatasetchanged","ondataavailable","ondatasetcomplete","onfilterchange","children","all","scopeName","onlosecapture","onscroll","ondrag","ondragend","ondragenter","ondragover","ondragleave","ondrop","onbeforecut","oncut","onbeforecopy","oncopy","onbeforepaste","onpaste","currentStyle","onpropertychange","tabIndex","accessKey","onblur","onfocus","onresize","clientHeight","clientWidth","clientTop","clientLeft","readyState","onreadystatechange","onrowsdelete","onrowsinserted","oncellchange","dir","scrollHeight","scrollWidth","scrollTop","scrollLeft","oncontextmenu","canHaveChildren","runtimeStyle","behaviorUrns","tagUrn","onbeforeeditfocus","isMultiLine","canHaveHTML","onlayoutcomplete","onpage","onbeforedeactivate","contentEditable","isContentEditable","hideFocus","disabled","isDisabled","onmove","oncontrolselect","onresizestart","onresizeend","onmovestart","onmoveend","onmouseenter","onmouseleave","onactivate","ondeactivate","onmousewheel","onbeforeactivate","onfocusin","onfocusout","uniqueNumber","uniqueID","nodeType","parentNode","childNodes","attributes","nodeName","nodeValue","firstChild","lastChild","previousSibling","nextSibling","ownerDocument","prefix","localName","namespaceURI","textContent","dataFld","dataSrc","dataFormatAs","role","ariaBusy","ariaChecked","ariaDisabled","ariaExpanded","ariaHaspopup","ariaHidden","ariaInvalid","ariaMultiselectable","ariaPressed","ariaReadonly","ariaRequired","ariaSecret","ariaSelected","ie8_attributes","ariaValuenow","ariaPosinset","ariaSetsize","ariaLevel","ariaValuemin","ariaValuemax","ariaControls","ariaDescribedby","ariaFlowto","ariaLabelledby","ariaActivedescendant","ariaOwns","ariaLive","ariaRelevant","ie9_tagName","ie9_nodeName","onabort","oncanplay","oncanplaythrough","onchange","ondurationchange","onemptied","onended","onerror","oninput","onload","onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange","onreset","onseeked","onseeking","onselect","onstalled","onsubmit","onsuspend","ontimeupdate","onvolumechange","onwaiting","constructor","onmspointerdown","onmspointermove","onmspointerup","onmspointerover","onmspointerout","onmspointercancel","onmspointerhover","onmslostpointercapture","onmsgotpointercapture","onmsgesturestart","onmsgesturechange","onmsgestureend","onmsgesturehold","onmsgesturetap","onmsgesturedoubletap","onmsinertiastart","onmstransitionstart","onmstransitionend","onmsanimationstart","onmsanimationend","onmsanimationiteration","oninvalid","xmsAcceleratorKey","spellcheck","onmsmanipulationstatechanged","oncuechange","type","value","name","status","form","ie9_type"
for ($a = 0;$a -lt $attributs.Count; $a++){
if($web_element.GetAttribute($attributs[$a].Split(":")[0].TrimEnd(" ")).Length -gt 0){
Write-Host $attributs[$a].PadRight(28, " ") ": " $web_element.GetAttribute($attributs[$a].Split(":")[0].TrimEnd(" "))
}}}

get-all-attribute-web-SE-elements ($Driver.FindElementsByClassName("button")[1])
  • Вопрос задан
  • 363 просмотра
Подписаться 3 Простой Комментировать
Решения вопроса 1
@IvanSstarr Автор вопроса
Написал функцию (костыль), проблема частично решена

function get-all-attribute-web-SE-elements($web_element){
$attributs = "className","id","tagName","parentElement","style","onhelp","onclick","ondblclick","onkeydown","onkeyup","onkeypress","onmouseout","onmouseover","onmousemove","onmousedown","onmouseup","document","title","language","onselectstart","sourceIndex","recordNumber","lang","offsetLeft","offsetTop","offsetWidth","offsetHeight","offsetParent","innerHTML","innerText","outerHTML","outerText","parentTextEdit","isTextEdit","filters","ondragstart","onbeforeupdate","onafterupdate","onerrorupdate","onrowexit","onrowenter","ondatasetchanged","ondataavailable","ondatasetcomplete","onfilterchange","children","all","scopeName","onlosecapture","onscroll","ondrag","ondragend","ondragenter","ondragover","ondragleave","ondrop","onbeforecut","oncut","onbeforecopy","oncopy","onbeforepaste","onpaste","currentStyle","onpropertychange","tabIndex","accessKey","onblur","onfocus","onresize","clientHeight","clientWidth","clientTop","clientLeft","readyState","onreadystatechange","onrowsdelete","onrowsinserted","oncellchange","dir","scrollHeight","scrollWidth","scrollTop","scrollLeft","oncontextmenu","canHaveChildren","runtimeStyle","behaviorUrns","tagUrn","onbeforeeditfocus","isMultiLine","canHaveHTML","onlayoutcomplete","onpage","onbeforedeactivate","contentEditable","isContentEditable","hideFocus","disabled","isDisabled","onmove","oncontrolselect","onresizestart","onresizeend","onmovestart","onmoveend","onmouseenter","onmouseleave","onactivate","ondeactivate","onmousewheel","onbeforeactivate","onfocusin","onfocusout","uniqueNumber","uniqueID","nodeType","parentNode","childNodes","attributes","nodeName","nodeValue","firstChild","lastChild","previousSibling","nextSibling","ownerDocument","prefix","localName","namespaceURI","textContent","dataFld","dataSrc","dataFormatAs","role","ariaBusy","ariaChecked","ariaDisabled","ariaExpanded","ariaHaspopup","ariaHidden","ariaInvalid","ariaMultiselectable","ariaPressed","ariaReadonly","ariaRequired","ariaSecret","ariaSelected","ie8_attributes","ariaValuenow","ariaPosinset","ariaSetsize","ariaLevel","ariaValuemin","ariaValuemax","ariaControls","ariaDescribedby","ariaFlowto","ariaLabelledby","ariaActivedescendant","ariaOwns","ariaLive","ariaRelevant","ie9_tagName","ie9_nodeName","onabort","oncanplay","oncanplaythrough","onchange","ondurationchange","onemptied","onended","onerror","oninput","onload","onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange","onreset","onseeked","onseeking","onselect","onstalled","onsubmit","onsuspend","ontimeupdate","onvolumechange","onwaiting","constructor","onmspointerdown","onmspointermove","onmspointerup","onmspointerover","onmspointerout","onmspointercancel","onmspointerhover","onmslostpointercapture","onmsgotpointercapture","onmsgesturestart","onmsgesturechange","onmsgestureend","onmsgesturehold","onmsgesturetap","onmsgesturedoubletap","onmsinertiastart","onmstransitionstart","onmstransitionend","onmsanimationstart","onmsanimationend","onmsanimationiteration","oninvalid","xmsAcceleratorKey","spellcheck","onmsmanipulationstatechanged","oncuechange","type","value","name","status","form","ie9_type"
for ($a = 0;$a -lt $attributs.Count; $a++){
if($web_element.GetAttribute($attributs[$a].Split(":")[0].TrimEnd(" ")).Length -gt 0){
Write-Host $attributs[$a].PadRight(28, " ") ": " $web_element.GetAttribute($attributs[$a].Split(":")[0].TrimEnd(" "))
}}}

Запускаем функцию:
get-all-attribute-web-SE-elements ($Driver.FindElementsByClassName("button")[1])

Получаем:
5c6d16ba25272859875608.jpeg
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 2
@azarij
В меру опытный никто
вот тут обсуждают:

https://stackoverflow.com/questions/27307131/selen...

p.s. не смотрите, что там про питон. селениум, как я понимаю, везде одинаковый.
Ответ написан
емнип InternerExplorer.Application это COM а openqa.Selenum типизированный - у него toString() короче и методов меньше. InternetExplorer это вообще прокси на DOM API древние
https://developer.mozilla.org/en-US/docs/Web/API/D... -
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы
18 дек. 2024, в 12:39
1000 руб./за проект
18 дек. 2024, в 12:37
10000 руб./за проект
18 дек. 2024, в 12:22
5000 руб./за проект