首页 > 解决方案 > InternetExplorer html attribute change

问题描述

The source webpage contains an input element with aria-expanded='false' and aria-activedescendant="Listbox_18--item-0"

when i change this attribute to 'true' (programmatically) it does expand on the open IE. also was able to change 'Listbox_18--item-3'.

but i am unable to trigger the event after the change. below is my VBA code.

IE.Document.body.getElementsByTagName("input")(0).Focus
Debug.Print IE.Document.body.getElementsByTagName("input")(0).setAttribute("aria-expanded", "true")
Debug.Print IE.Document.body.getElementsByTagName("input")(0).setAttribute("aria-activedescendant", "Listbox_18--item-3")
Debug.Print IE.Document.body.getElementsByTagName("input")(0).setAttribute("aria-expanded", "false")

标签: vbainternet-explorerdom

解决方案


Allright, so this is what is happening on the page.

You're dealing with elements in the DOM that use javascript to listen for events then trigger functions and then ultimately call on an AJAX function to return data to the web page without re-loading.

That means you cant just set attributes. Since the act of setting the attribute doesn't register the event / values in the web app's variables.

So try something like this, you're going to have emulate the actions on the page in order to generate the AJAX response, especially since SW's website is using a generated QSI id thingy, to specify what the page's selections are.

So the workflow on the page is: page loads, events are set on elements, script resources hold functions. User clicks the element, event is fired, selection values are noted, the script resource creates the random id, the random id is an input to the ajax http request, and then it returns the price values from the matching id's.

I do something like this in the console of DevTools, and it emulates the user clicking the item. Now you see the page does the Ajax request and returns the prices.

document.querySelectorAll('#Listbox_10--item-3 > button')[0].click();

In something more advanced like puppeteer, you can actually set request interception on to look for that request on the page, from the ajax, but in VBA, you're just gonna have to wait for the load, and look for the page to update it's HTML.

Now if you had a way to capture the ID then send it to the server as a parameter like you see in DevTools -- You could send it using MS XML HTTP and get that nice JSON response.


推荐阅读