getElementbyID(...) in a webbrowser (NOT IE)

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Locked
User avatar
BSH-GIT-PL-pss
Posts: 2
Joined: Tue Sep 22, 2015 10:27 pm

getElementbyID(...) in a webbrowser (NOT IE)

Post by BSH-GIT-PL-pss »

Hello everyone,

I hope I can get some help with my problem.

Basically, what I want is to open a webpage in a webbrowser embedded in a Form window, and to enter a value into the textbox with the id "login-name". The code looks as follows:
PowerShell Code
Double-click the code block to select all.
$browser = New-Object System.Windows.Forms.WebBrowser
$browser.IsWebBrowserContextMenuEnabled = $true
$browser.URL = "webpage-here"
$browser.Width = 1325
$browser.Height = 725
$browser.Location = "25, 50"
$browser.IsAccessible = $true
$mainForm.Controls.Add($browser)
sleep -milliseconds 5000 #wait for browser to load
$browser.Document.getElementById('login-name').value = $User
Obviously, I want to write the value stored in "$User" into the textbox with the ID "login-name". Please note that this is working when using the InternetExplorer Application, so my error is not a wrong ID or something like that.

The generated output just says, that the "getElementByID" returns NULL in this case. Therefore, "$User" can't be written into the textbox. The webpage itself is displayed correctly.

I hope anyone can help me with this problem. If I missed an answer to this problem which is posted in this forum, please feel free to just post the link below.

Thanks in advance :)


Regards, Kevin

User avatar
SAPIEN Support Forums
Posts: 945
Joined: Wed Dec 03, 2014 2:26 pm

getElementbyID(...) in a webbrowser (NOT IE)

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, buecheleke.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***

jvierra
Posts: 14614
Joined: Tue May 22, 2007 9:57 am
Answers: 2
Has voted: 1 time
Been upvoted: 3 times
Contact:

Re: getElementbyID(...) in a webbrowser (NOT IE)

Post by jvierra »

place URL assignment into a button or into the form load. You cannot navigate the control until the form is complete.

User avatar
BSH-GIT-PL-pss
Posts: 2
Joined: Tue Sep 22, 2015 10:27 pm

Re: getElementbyID(...) in a webbrowser (NOT IE)

Post by BSH-GIT-PL-pss »

Hi, sorry for the delayed answer.

You were right (of course :P).

My main problem was that I wanted everything to happen in the background and then make it visible when the login routine is over.

I'm gonna change my GUI to make it work, that's no prob for me. Thanks again for your help!

Locked