Share via

edge browser control executejavascript method

Anonymous
2024-06-19T05:36:34+00:00

jsCode = "document.querySelector(""#form_arap_bxbusitem\&childform2 > div > div > div.vat_amount.js-type-number.form-item > div.form-item-control > div > span > div > div > div > div > input"").value = 8888"

me.edgebrowser.executejavascript(jscode)

executed successfully in chrome devtools console,but failed in vba

web page with frames

Microsoft 365 and Office | Access | Other | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2024-06-28T02:47:16+00:00

https://filetransfer.io/data-package/DoMYNUWt#link

thanks

用友的bip

Thanks for your feedback.

I have found two level iframes nested.

So in Access webview need grasp the element from the first level.

<script>

//<iframe id="forwardFrame" src="./新增_境内差旅费报销单_files/index.html" frameborder="0" height="100%" width="100%"></iframe>

///storage/emulated/0/Download/2/新增_境内差旅费报销单.html

//<iframe fieldid="main_iframe" id="mainiframe" class=" iframeIndex" frameborder="0" scrolling="0" src="./index(10).html" style="width: 100%; height: 100%;">

///storage/emulated/0/Download/2/新增_境内差旅费报销单_files/index.html

///storage/emulated/0/Download/2/新增_境内差旅费报销单_files/index(10).html

function myFunction() {

var elmnt = document.getElementById('forwardFrame'); 

 alert(elmnt.outerHTML)

var elmnt2 = elmnt.contentWindow.document.getElementsByTagName("iframe")[0];

 alert(elmnt2.outerHTML)

var elmnt3 = elmnt2.contentWindow.document.getElementsByTagName("input")[3];

elmnt3.value=888; 

}

// var elmnt3 = elmnt2.contentWindow.document.body;

 //alert(elmnt3.outerHTML)

/*

var elmnt = iframe.contentWindow.document.getElementsByTagName("input")[3]; 

alert(elmnt.outerHTML)

elmnt.value=888

*/

</script>

https://filetransfer.io/data-package/yS8d5EQq#link

js in VBA may like this.

jsCodes="var elmnt = document.getElementById('forwardFrame');

 alert(elmnt.outerHTML)

var elmnt2 = elmnt.contentWindow.document.getElementsByTagName(""iframe"")[0];

 alert(elmnt2.outerHTML)

var elmnt3 = elmnt2.contentWindow.document.getElementsByTagName(""input"")[3];

elmnt3.value=888; "

//单据日期

I have dissabled all css and js

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

21 additional answers

Sort by: Most helpful
  1. Anonymous
    2024-06-24T01:40:01+00:00

    i executed the code which you gave it to me,but failed.

    var iframe1 = document.getElementById('mainiframe');

    if (iframe1 && iframe1.contentWindow && iframe1.contentDocument) {

    var inputElement = iframe1.contentDocument.querySelector('#form_head > div > div > div.zy.js-type-refer.form-item > div.form-item-control > div > span > div > div > div.wui-col-xs-12.wui-col.wui-col-xs-12.refer.clearfix.false.refer-input-common > div > ul > li.selected-input > div > input');

    if (inputElement) {

    inputElement.value = 'Hello from iframer'; // Set the value 
    
    console.log('Input value set successfully.'); 
    

    } else {

    console.error('Input element not found.'); 
    

    }

    } else {

    console.error('Unable to access the iframe or its document.');

    }

    the code above runed in devtools console forwardFrame successfully,but failed in vba executejavascript.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2024-06-21T22:48:46+00:00

    failed

    ?

    Have you run the codes I gave you?

    maybe the reason is iframe

    me.edgebrowser.executejavascript(jscode) should execute in correct iframe

    Image

    try

    contentWindow.

    Yes,iframe some special.

    https://www.w3schools.com/howto/tryit.asp?filename=tryhow\_js\_element\_iframe

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2024-06-21T01:56:40+00:00

    failed

    maybe the reason is iframe

    me.edgebrowser.executejavascript(jscode) should execute in correct iframe

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2024-06-20T23:14:04+00:00

    Try dump error.

    jsCode = "window.addEventListener('error',function(e){

        alert(e.filename+'\nLine '+e.lineno+'\n'+e.message);
    
    });"
    

    me.edgebrowser.executejavascript(jscode)

    jsCode ="document.querySelector(""#form_arap_bxbusitem\&childform2 > div > div > div.vat_amount.js-type-number.form-item > div.form-item-control > div > span > div > div > div > div > input"").value = 8888;"

    me.edgebrowser.executejavascript(jscode)

    Was this answer helpful?

    0 comments No comments