The Chrome element is as follows:
input type="Radio" name="template" value="Choice" tabindex="13"
onclick="javascript:setTemplateType(this.value);">
The VBA code I am using is as follows:
Private Sub SAMDataInput()
Dim keys As New SeleniumWrapper.keys
driver.FindElementByName("template").Click
driver.FindElementByName("template").SendKeys "Choice"
End Sub
I always want "Choice" to be selected.
Related
I've been trying to use a combobox to show/hide a PDF viewer that I've added into a MS Access form.
When I use the form_current event, then the form only updates when I move between the data entries. When I use the afterupdate event, the same code does nothing at all.
Does anyone have a fix? The code I have used is below, which I have tried both the AfterUpdate event for the Browser and the Form_Current event for the whole form
Private Sub PDFT900_AfterUpdate() / Private Sub Form_Current()
Dim ESNComb As String
ESNComb = Me.ESNCombo.Column(1)
If ESNComb Like "9????" Then
Me.PDFT900.Visible = True
Else
Me.PDFT900.Visible = False
End If
End Sub
In the code below, I'm hiding and showing the Adobe PDF Reader ActiveX control named, "AcroPDF0". Since the Like operator returns true on an expression match and false on a mismatch or no match, it serves as a simple boolean switch for the visible property. I've used the (*) wild card instead of (?). It works {shrug}. See demonstration images below.
Private Sub ESNCombo_AfterUpdate()
'AcroPDF0.Visible = ESNCombo.Text Like "P*"
AcroPDF0.Visible = ESNCombo.Column(0) Like "P*"
AcroPDF0.src = acroPDFOSrc
End Sub
ComboBox List Items
"File Browser" Selected in ComboBox
Toggled ComboBox back to "PDFT900"
I'm trying to make it so I can have several text boxes in my form show pieces of information from a specific webpage. For example, would there be a way I would be able to retrieve the title of this question to a variable with the click of a button in Visual Basic?
It not hard but you have to look at the source page, and identify the elements.
In nicely formed pages, usually the div elements have a tag ID, but often they don't, so you have to grab say by a attribute name - often you can use the class name of the div in question.
So, to grab the Title, and you question text of this post?
This works:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim xDoc As New Xml.XmlDocument
Dim strURL As String = "https://stackoverflow.com/questions/55753982"
Dim xWeb As New WebBrowser
xWeb.ScriptErrorsSuppressed = True
xWeb.Navigate(strURL)
Do Until xWeb.ReadyState = WebBrowserReadyState.Complete
Application.DoEvents()
Loop
Dim HDoc As HtmlDocument = xWeb.Document
Debug.Print(HDoc.GetElementById("question-header").FirstChild.InnerText)
Debug.Print(FindClass(HDoc, "post-text"))
End Sub
Function FindClass(Hdoc As HtmlDocument, strClass As String) As String
' get all Divs, and search by class name
Dim OneElement As HtmlElement
For Each OneElement In Hdoc.GetElementsByTagName("div")
If OneElement.GetAttribute("classname") = strClass Then
Return OneElement.InnerText
End If
Next
' we get here, not found, so return a empty stirng
Return "not found"
End Function
OutPut:
(first part is title question)
Is there a way to retrieve some text from a webpage to a textbox in VB?
(second part is question text)
I'm trying to make it so I can have several text boxes in my form show pieces of
information from a specific webpage. For example, would there be a way I would be
able to retrieve the title of this question to a variable with the click of a button
in Visual Basic?
I have a connection to an internet explorer webpage but i cannot seem to "click" a specific link using vba7 in access. I've tried loads of options like getelementsbyclassname. Here's the source code from the webpage:
<tr>
<td valign=bottom class="formbutton" align=center colspan=2>
view
</td>
</tr>
As you can see it has no name nor a usable hyperlink and the purpose of this link is to submit the filled-out form and give it a unique number on a new web page.
Can you please help me in VBA 7 for Access 2007 to come up with a vba code that works?
Many thanks!
The following should work assuming you have a pointer to the InternetExplorer object already.
Public Sub ClickElement()
'Assuming you already have an IE object
Dim Elements As Object
Dim Element As Object
'get all 'A' tags, which the hyperlink is part of
Set Elements = IE.Document.getElementsByTagName("a")
For Each Element In Elements
'I believe the element you want to click appears as 'View' on screen
If Element.InnerText = "View" Then
'Usually a good idea to give the element focus and
'possibly fire the OnClick event, but sometimes not needed
Element.Focus
Element.Click
Element.FireEvent ("OnClick")
Exit For
End If
Next
End Sub
Can i have a link between a button on an IE page and a visio event ? ( for example : changing the color of a shape just by a click on a button on the IE page)
Not really very easy unless you have access to the HTML content in IE as well, but you could use a VBA class which implements a "withevents" private variable to capture a reference to a particular element on the page, and which has an event handler to respond to browser-based events. Eg. in a class "clsHTML":
Private WithEvents el As MSHTML.HTMLInputElement
Public Sub SetElement(t As MSHTML.HTMLInputElement)
Set el = t
End Sub
Private Function el_onchange() As Boolean
Debug.Print "captured change: value = " & el.Value
End Function
In other code, create an instance of the class and call "SetElement" using a reference to an element on the page in IE:
Dim objHTML As clsHTML 'global variable
Sub TestEvents()
Dim IE As Object
'set up your IE reference....
Set objHTML = New clsHTML
objHTML.SetElement IE.document.getElementById("tester2")
Debug.Print "set capture"
End Sub
In this instance you're capturing the "change" event on a textbox, but other elements will expose different events....
Edit: I tested this in Excel, but I'm assuming something similar will also work in Visio.
Edit2: you would probably be much better off creating a form in Visio to handle this than sticking with automating IE.
yes you should check the get started documentation of jquery
html :
<button id="mybutton" />
<div id="myshape">blabla</div>
javascript :
$('#mybutton').click(function() {
$('#myshape').css('background-color', '#555555');
});
My problem is: I have a stripped down default.aspx page. Aside from a element, almost ALL the functionality has to be in the code-behind in aspx.vb.
The program retreives information from a database and compares this to another list of tables, number of both lists can vary.
So I need to "bind" a dynamic number of RadioButtonLists to the asp:table element controls, and I need to create a dynamic number of ListItems to each RadioButtonList created. Later, I need to be able to access the selected value of each in order to decide future functions in the database.
An example of the code is like this:
aspx file:
<asp:table ID="table1" runat="server">
aspx.vb file (code-behind):
Sub createHtmlTables()
For i = 0 To productIndex.Count - 1
''//create a RadioButtonList for each i
Dim row As New TableRow
Dim cell As New TableCell
For k = 0 To productTypeAmountIndex.Count - 1
''//create a ListItem(radiobutton)
''//for each k and include it in the RadioButtonList
''//assign a value (for example name) of the product as
''//the ListItems ID to retreive it later
Next
''//add the RadioButtonList to cell.controls etc
Table1.Rows.Add(row)
Next
End Sub
Sub addToDb()
For i = 0 To productIndex.Count - 1
''//get the RadioButtonList for each i
''//and return the value of the selected radiobutton
''//within the list to a variable
Next
End Sub
Sorry if this is long and confusing, but as I can't even form my questions right yet, I tried to include as much information as possible. Basically I just need an example of how and which methods to use to get all that working.
Update:
Everyone keeps telling me that going for tables to begin with was a mistake, but some place I found claimed that you can't customize datagrid looks as easily as you can with tables. I guess I'll start the whole thing from scratch then.
Thing is that the UI should be as graphically pleasing as possible, with the tables I can do all sorts of neat things such as colouring the cells according to the information inside etc.
Anyway, thanks but not what I was looking for but I'll try to remake the thing with datagrid / gridview and see what happens. Might take a few days before I learn enough of them to use them and get back here.
Rather than a table, you'll have better luck with a true server control like gridview or datagrid, or repeater. Then you can just wire up the datasource property on your control.
For all dynamic controls, remember that you have to recreate them every time you do a postback. This may sound odd, but the trick is the every request to the server, including postbacks, uses a different instance of your page class. When that request/postback finishes the page instance used for that request is destroyed. The only things left active are the session and the cache.
This is my .aspx code.
<asp:Table ID="Questions" runat="server">
</asp:Table>
<asp:Button ID="SaveButton" runat="server" Text="Save" />
This is my code behind file code.
I have added dynamic drop-down list.
On save button click, I am retrieving selected value.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim NewRow As New TableRow
Dim NewCell As New TableCell
Dim rblOptions As New RadioButtonList
rblOptions.ID = "Option1"
rblOptions.Items.Add(New System.Web.UI.WebControls.ListItem("1", "1"))
rblOptions.Items.Add(New System.Web.UI.WebControls.ListItem("2", "2"))
rblOptions.Items.Add(New System.Web.UI.WebControls.ListItem("3", "3"))
NewCell.Controls.Add(rblOptions)
NewRow.Cells.Add(NewCell)
'Questions is a table
Questions.Rows.Add(NewRow)
End Sub
Protected Sub SaveButton_Click(sender As Object, e As EventArgs) Handles SaveButton.Click
If Page.IsValid Then
Dim rbl As RadioButtonList = DirectCast(Questions.FindControl("Option1"), RadioButtonList)
If rbl.SelectedValue.ToString = "ExpectedValue" Then
End If
End If
End Sub