mardi 11 juin 2019

How to select each option in dropdown list and click a button (same origin policy issue)

I need a code that loops through options in a < select > object on a web page, selects each option and clicks "Show" button to show some data related to the selected option. I started with this code:

Set periodSelector = ie.document.getElementById("period")
For Each Period In periodSelector.Options
    Period.Selected = True
    Application.Wait (Now + TimeValue(waittime))
Next Period

It works well - the browser selects each option just fine. But when I add button.click to show the data related to the selected option, an error "Permission denied" occurs on the second selector loop (seems like it cannot use .select command anymore).

Set periodSelector = ie.document.getElementById("period")
For Each Period In periodSelector.Options
    Period.Selected = True
    Application.Wait (Now + TimeValue(waittime))
    ie.document.getElementsByTagName("input")(17).Click
    Application.Wait (Now + TimeValue(waittime))
Next Period

I guess it is due to same origin policy. Probably, when I click on the "Show" button, the page gets refreshed (although it is not really reloaded - the button uses scripts to retrieve some information and show it in a table below the button). How can I avoid this same origin policy issue and loop through the dropdown options?




Aucun commentaire:

Enregistrer un commentaire