-
Nov 22nd, 2019, 07:35 AM
#1
Thread Starter
Junior Member
can't set radio button to checked in group via webbrowser control
Having trouble setting a radio button via a webbrowser control in visual basin .net. This is the HTML code I'm trying to act upon!
<td align="right">
Afficher statuts :
</td>
<td>
<label for="Company">
<input type="radio" id="Services" value="true" name="requestinfo_0" />
Company
</label>
<label for="Partener">
<input type="radio" id="Workload" value="false" name="requestinfo_0" />
Partener
</label>
<label for="All">
<input type="radio" id="All" value="" name="requestinfo_0" />
All
</label>
The suggested solution I found searching shows it should work like this! But doesn't!
WebBrowser1.Document.GetElementById("Workload").SetAttribute("Checked", True)
But I believe I would need to specify the name as well as from what I can tell its possible to have more than 1 ID as Workload but in a radio button with a different name. But I can't see where or how to write the code accordingly!
I'm doing this in Visual studio 2019 in Visual basic!
Thanks Pete
Last edited by peterg2000; Nov 22nd, 2019 at 07:55 AM.
-
Nov 22nd, 2019, 08:14 AM
#2
Re: can't set radio button to checked in group via webbrowser control
Try
SetAttribute("Checked", "Checked")
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 22nd, 2019, 09:42 AM
#3
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
Originally Posted by .paul.
Try
SetAttribute("Checked", "Checked")
Same result! I've tried different options , SetAttribute("Checked", "True") or SetAttribute("Checked", True).
I`m wondering if I`d have to click the button instead of setting it! Not sure of the coding though!
Pete
-
Nov 22nd, 2019, 10:10 AM
#4
Re: can't set radio button to checked in group via webbrowser control
I just tried it using just the code you posted, and it worked fine. The id of each element should be unique. There should not be more than one element with the id "Workload" in your page.
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 22nd, 2019, 10:15 AM
#5
Re: can't set radio button to checked in group via webbrowser control
You need to be sure your page is fully loaded before setting it...
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Document.GetElementById("Workload").SetAttribute("Checked", True)
End Sub
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 22nd, 2019, 10:37 AM
#6
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
Originally Posted by .paul.
I just tried it using just the code you posted, and it worked fine. The id of each element should be unique. There should not be more than one element with the id "Workload" in your page.
Yeah , my bad as I was fooled by having one Workload and the other workload. Missed the case change on the W.
Pete
-
Nov 22nd, 2019, 10:39 AM
#7
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
The code to change the Radio button is in the sub pointed to by addhandler statement! So I know the page has loaded!
Pete
-
Nov 22nd, 2019, 10:53 AM
#8
Re: can't set radio button to checked in group via webbrowser control
If that’s the wb_documentcompleted method, you’ll find it fires before the page is ready. Search for readystate
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 22nd, 2019, 11:11 AM
#9
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
The code to change the Radio button is in the sub pointed to by addhandler statement! So I know the page has loaded!
Pete
-
Nov 22nd, 2019, 02:09 PM
#10
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
I have a second part to this code that requests a download of an Excel file once the radio boxes are selected! And it fires properly! Its right after the WebBrowser1.Document.GetElementById("Workload").SetAttribute("Checked", True)
Dim teststr As String
For Each el As HtmlElement In els teststr = el.GetAttribute("href")
'Debug.Print(el.GetAttribute("href"))
If teststr.Contains("/exportExcelDetailled") Then
el.InvokeMember("click")
End If
Next
Pete
Last edited by peterg2000; Nov 25th, 2019 at 07:25 AM.
-
Nov 25th, 2019, 08:37 AM
#11
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
Solved the problem by using a click event! Works fine now!
For Each curElement As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "Services" Then
curElement.SetAttribute("checked", "checked")
End If
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "Radio3" Then
curElement.SetAttribute("checked", "checked")
End If
If curElement.GetAttribute("type") = "radio" AndAlso curElement.GetAttribute("id") = "all" Then
curElement.SetAttribute("checked", "checked")
End If
Next
Pete
-
Nov 25th, 2019, 08:37 AM
#12
Thread Starter
Junior Member
Re: can't set radio button to checked in group via webbrowser control
Thanks to those who tried to help!
Pete
Last edited by peterg2000; Nov 25th, 2019 at 08:38 AM.
Reason: Double post!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|