I need help with the automated filling of a web page. I want to open the page in Edge, enter something in a field and then save what happens through a button and then close the tab again. Currently my code looks like this:
[system.Diagnostics.Process]::Start("msedge","https://mypage.com")
Sleep 3
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('MyTab')
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("{H}")
$wshell.SendKeys("{e}")
$wshell.SendKeys("{l}")
$wshell.SendKeys("{l}")
$wshell.SendKeys("{o}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("%n{TAB}")
$wshell.SendKeys("{ENTER}")
As you can see I move on the page with tab and make all inputs by SendKeys, but here there is surely a better variant?
The field where the entries are to be made, I have already figured out and is:
<div class="DialogInput_Wrapper _DialogLayout Panel Focusable"><input type="text" name="personaName" class="DialogInput DialogInputPlaceholder DialogTextInputBase Focusable" tabindex="0" value="Goodbye"></div>
respectively
<input type="text" name="personaName" class="DialogInput DialogInputPlaceholder DialogTextInputBase Focusable" tabindex="0" value="Goodbye">
The button to save is:
<button type="submit" class="DialogButton _DialogLayout Primary Focusable" tabindex="0">Save</button>
Can I even make entries this way or is the "tab" variant the seemingly best solution? Can it work at all if I make it a ComObject?
Please give some hints or help. Thank you
Kind regards Roman
I had tried ie-code, but then Explorer does not display the page correctly. The code used was:
$mytext="hello"
$url = "https://mypage.com"
$ie = New-Object -com InternetExplorer.Application
$ie.visible = $true
$ie.navigate($url)
while($ie.Busy) { Start-Sleep -Milliseconds 100 }
$ie.document.IHTMLDocument3_getElementByName("personaName").value = $mytext
$ie.document.IHTMLDocument3_getElementById("Save").click()
This would, I think, theoretically be the right code, but how can I pick out the individual components of the web page for a ComObject, similar to the code with:
$ie.document.IHTMLDocument3_getElementByName("personaName").value = $mytext