Jump to content
mexykanu

IE.au3 - Cannot get dataset value from any page or element - IE11

Recommended Posts

mexykanu

Hello,

The problem is as follows: From an Internet Explorer DOM Element Object, i cannot get a dataset attribute's value (HTML5 data-*), regardless of the website i try.

I've only tried doing this in Autoit v3.3.12.0, IE 11, Windows 10 x64.

The following code does not work as expected:

#Include <ie.au3>
Global Const $base_url = 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset'

$oIE = _IEAttach($base_url, 'url')

if @error then
    $oIE = _IECreate($base_url)
EndIf

Local $result = $oIE.document.getElementsByTagName('html').item(0).dataset.ffoOpensans

MsgBox(0, '', $result)

The MessageBox is empty, but should contain the string "true".

 

Expected behaviour:

1. In your favorite browser, go to: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

2. Open the Dev Tools, go to Console, paste this: document.getElementsByTagName('html').item(0).dataset.ffoOpensans

Result: You will be returned with the string "true"

 

Is this an Autoit Bug, or should i be doing something differently ?

 

Thank you.

 

Edited by mexykanu

Share this post


Link to post
Share on other sites
mexykanu

Update:

I'm 99% sure this is an Autoit Bug. Most likely, dataset has not been implemented yet.

I made this deduction because my version of Autoit still uses document.parentWindow.execscript instead of document.parentWindow.eval, but... execscript isn't available in IE11 (which i'm using)... Therefore this command is hardcoded in AutoIt  v3.3.12.0 (which i'm using). If this is the case, then there should be many more missing properties or deprecated and unchanged commands. waiting to be found.

More info: https://msdn.microsoft.com/en-us/library/aa741364(v=vs.85).aspx

 

Right now i've got to this workaround, adapted from here https://stackoverflow.com/questions/26021813/ie-com-automation-how-to-get-the-return-value-of-window-execscript-in-powersh:

#Include <ie.au3>
Global Const $base_url = 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset'

$oIE = _IEAttach($base_url, "url")

if @error then
    $oIE = _IECreate($base_url)
EndIf

Local $command = 'document.body.setAttribute("Result", (function(){return document.getElementsByTagName(''html'').item(0).dataset.ffoOpensans})())'

$oIE.document.parentWindow.execscript($command)

Local $result = $oIE.document.getElementsByTagName('body').item(0).getAttribute('Result')

MsgBox(0, '', $result)

There is another slightly simpler, similar workaround, from our Chinese friends. The link that follows is not the original one. Also, their code does not work, i've fixed it below https://jingyan.baidu.com/article/9989c74604d644f648ecfe03.html

#Include <ie.au3>
Global Const $base_url = 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset'

$oIE = _IEAttach($base_url, "url")

if @error then
    $oIE = _IECreate($base_url)
EndIf

Local $command = 'document.ScriptReturn = document.getElementsByTagName(''html'').item(0).dataset.ffoOpensans'

$oIE.document.parentWindow.execscript($command)

Local $result = $oIE.document.ScriptReturn

MsgBox(0, '', $result)

All of the above codes, work.

This issue is still unresolved. I'm waiting for an answer from someone more experienced than me, that maybe has some better ideas.

Edited by mexykanu

Share this post


Link to post
Share on other sites
mexykanu
5 hours ago, Danp2 said:

There is something else at play here. The script does work correctly *after* you Open the Dev Tools, go to Console, paste this: document.getElementsByTagName('html').item(0).dataset.ffoOpensans.

Well, this is interesting! Thank you for this information. If this is the case, then there are one or more differences between the COM Object methods and the internal IE 11 methods, or something of this nature. Something does not add up still, and that is this link that i've posted earlier:  https://msdn.microsoft.com/en-us/library/aa741364(v=vs.85).aspx

Therefore, one more workaround can be used:

#Include <ie.au3>
Global Const $base_url = 'https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset'

$oIE = _IEAttach($base_url, 'url')

if @error then
    $oIE = _IECreate($base_url)
EndIf

Local $command = 'document.getElementsByTagName("html").item(0).dataset.ffoOpensans'

$oIE.document.parentWindow.execscript($command)

Local $result = $oIE.document.getElementsByTagName('html').item(0).dataset.ffoOpensans

MsgBox(0, '', $result)

One more problem arises from this workaround: How do we simplify the code ?

Is there a way of running the following code (i've already tried brackets and parantheses) ?

Local $command = 'document.getElementsByTagName("html").item(0).dataset.ffoOpensans'

$oIE.document.parentWindow.execscript($command)

Local $result = $oIE.$command

 

This issue is still unresolved.

Share this post


Link to post
Share on other sites
mexykanu
On 11/22/2017 at 3:03 PM, Danp2 said:

You could fall back to using GetAttirbute instead of dataset --

Local $result = $oIE.document.getElementsByTagName('html').item(0).getAttribute('data-ffo-opensans')

 

This works ! Thank you for your help !

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.