vb.net how to get value of <strong> using htmlagilitypack - vb.net

How to get value under using hhtmlagilitypack. by the way there are many<tr><td> from this site, so would be much better if I can get the specific value under this "Social Security Number"
<tr><td><span>Social Security Number</span></td><td><strong>524-23-6748</strong></td></tr>
I tried using this code but no luck
Dim webGet As New HtmlWeb
Dim doc As HtmlDocument = webGet.Load("https://www.fakeaddressgenerator.com/World_Address/get_us_address/city/Chicago")
Dim work As HtmlNodeCollection = doc.DocumentNode.SelectNodes("/html/body/div[1]/div[3]/div[1]/div/div/div[2]/div[1]/div[2]/table/tbody/tr[6]/td[2]/strong")
TextBox1.Text = work.First().Attributes("value").Value

This one is different to the last; the xpath is right except for the tbody. It's important to remember that the document inspector you see in a browser might not reflect the actual source, and the source is what HAP parses
Easiest way I find to debug these is to remove the trailing part of the path and look what I get in the locals window:
In terms of how to know if it's attibute values or inner text etc, that comes from looking at the structure of the HTML:
Yellow highlights are attributes (things between < and > that is in the form name="value" is an attribute name/value pair), red underlines innertexts (anything between > and <)
All in your code is right apart from the TBODY, and that you're trying to select the Value of an attribute called "value" but your strong doesn't have any attributes, it only has an inner text

Related

findelementsbycss in vba with selenium

i can't manage to extract certain links from a website with css.
i don't really know css yet either and am just finding my way around it.
i have 2 questions one specific how to find the element, and at the end again how to examine the element in css.
1.
Inspection of the site with markers
i am trying to get the two links marked in green, as marker i would like to use either the red marked link text or above it.
my attempted code:
Set Elements = GC.FindElementsByCss("table.TABLE tbody tr td p iframe ")
a = 0
For Each Element In Elements
ReDim Preserve href(a) As String
href(a) = Element.Attribute("innerText")
a = a + 1
Next Element
can i somehow examine the elements in vba?
if i know what is stored in them, i could search for the desired value under Value and then use the expression.
I think under Watches I once had the possibility to see all the different values for an element like innerText, href, outerhtml, innerhtml and so on.
In VBA Watches at the moment i only see a small overview

getting value of attribute to string vb.net

I want to get the value of the src attribute (https://www.google.com) to a string from a web browser HTML elements. The code of element is:
<img src="https://www.google.com" height="500" width="500">
Code I have tried is:
For Each o As HtmlElement In WebBrowser1.Document.GetElementsByTagName("img")
If o.GetAttribute("height") = "500" Then
Dim url As String = o.GetAttribute("src").ToString
Exit For
End If
Next
String url is empty every time I also tried to get url in textbox but its also empty.
problem is that is not a server side control, it is plain html. to make matters worse there are not classes or ID's to make it easier to isolate which control u want to target. Also javascript could be generating that image so that could make it harder.

Is it possible to colour a cell with value from data in Cognos BI?

Let me first be clear. I'm not asking about how I do conditional formatting in Cognos BI. If there were a simple Red/Amber/Green colour scheme, based upon value ranges then I could do that. If it were a static list of colours, which never changed, I could also do that.
What I am after is accessing a hex colour code that is stored in my database, and I want to use that colour as my table cell background colour. This is something I commonly do in SSRS reports, but cannot see a method for in Cognos BI.
Is this even possible?
You can do this via the HTML object in Cognos.
The HTML object can get its definition from one of the three main ways:
1) Hard-coded text
2) Data Item Value
3) Report Expression
Obviously the first method provides no way to dynamically set the value. I couldn't get the second one to work at all. I'm not yet sure why. However, I was able to use the third type to work to allow dynamic setting of a visual style.
For the solution we'll assume you have a data item called [Color] which pulls a string value from a database in the standard hex form that is used in CSS: #xxxxxx, e.g. #CCCCCC. For the purpose of this example we'll assume it is in query Query1. The following steps describe how to set it up.
1) Add an HTML item right above your list
2) Add another HTML item at the bottom of your list
3) In the top HTML item add a span tag with a unique id such as:
<span id="list">
4) In the bottom HTML item add a closing span tag
</span>
5) Add a third HTML item before all of the other HTML items
6) Set the 'Source Type' property of the HTML item to 'Report Expression'
7) In the Report Expression put the following code:
'<style>
#list td {
background-color: ' + [Query1].[Color] + '
}
</style>'
8) Select the Page object and set the Query property to Query1
9) Click on the Properties property. Check the Color column to give the page access to that query-sourced value.
Now you can dynamically set the column color based on a database provided value. We used the span to give us a way to isolate just the table cells we want to manipulate.
The technique isn't perfect. For instance, the header cells also get their background changed to the color in question, which may or may not be desirable. This is because Cognos doesn't use the th tag for headers but instead renders them as normal cells (td).
I know it's quite and old post but just for completeness I'll add the references to get this working in html, pdf and excel.
To get this working not only for html but also for pdf and excel use a rich text item instead of a html item.
You can use following code in a query item for instance:
<span style="display:block; background-color:' + [Query Subject].[Query Item] + '"> </span>
The query item must then contain a valid color (e.g. rgb(255,0,0)) etc. which is defined by your data source.
Dragging a rich text item in a list and changing it to data item value and selecting the query item will work.
By using the span it will work for excel too, however to make sure it follows the size of the upper object in the hierarchy (the list column or a table etc) you want the display:block style.
Instead of the space in between the > < you can use any other query item that you want to appear as text.

Pass parameter value to Revit family using .net api

I want to pass the parameter values to Revit family.I have spend many hours on google. In result i got few links which tells Read and Write Parameter Values with VB.NET
Read and Write Parameter Values with VB.NET
in this example we are fetching parameters and writing a value in text file called ParametersValue.txt. But i am confused, how should i pass this file to Revit?
I'm hoping someone can steer me in the right direction. I would really appreciate it!
One of the first things I would do after downloading the SDK mentioned in the previous post, is install the included revit lookup addin. This has been incredibly valuable in figuring what elements are called in the API, as well as determining which storage type the parameter is using. If all of the parameters you want to update are strings, those will be fairly straightforward to set from your text file. However, if,for example, the parameter value that you think is a string is actually set by an elementid, then there will be some coding involved to get the proper info to set the parameter value.
You can easily pass parameters to component families using "FamilyManager" class. The FamilyManager class provides access to family types and parameters. Just get the parameter and set its value. As we are working in family editor for component families, we have to load the parameter values in the project. I have tried this on Revit 2019. You have to
Open family in family editor
Activate the plugin
Click on Load into Project button on addins ribbon.
Then check the parameter value in the properties of that family.
Public Sub SetParamtersForComponentFamilies(ByVal doc As Document, ByVal parameterValue As String)
Dim f As Family = doc.OwnerFamily
Using trans As Transaction = New Transaction(doc, "Creating transaction for parameters")
trans.Start()
Dim familyMgr As FamilyManager = doc.FamilyManager
Dim n As Integer = familyMgr.Parameters.Size
Dim comment As FamilyParameter = familyMgr.get_Parameter(BuiltInParameter.ALL_MODEL_TYPE_COMMENTS)
familyMgr.Set(comment, parameterValue)
TaskDialog.Show("Paramters", "TypeComments : Updated")
trans.Commit()
End Using
End Sub
I use C# when writing Revit API code because that's what all the samples are written in, but I might be able to get you pointed in the right direction with some additional details. Are you looking to assign a value to a specific parameter? For example: Height=30"?
If so you first have to "get" the parameter. In the example in spidernet he goes through every parameter of a selected element:
Dim element As Autodesk.Revit.DB.Element = SelElement(cmdData.Application.ActiveUIDocument.Selection).Element 'Prompts you to select an element
For Each p As Parameter In element.Parameters 'Goes through every parameter in "element" and assigns the parameter to "p"
If p.Definition.Name = "Height" Then 'Check if "p" is the name you want, "Height"
p.Set(2.5) 'Because Revit knows FEET, so in order to type in 30in you use 2.5
End If
Next 'Loop through parameters
If you're looking for it to do something else, please post again.
Also, not sure you're aware, but a blog that is FULL is great Revit API info is Jeremy Tammik's: http://thebuildingcoder.typepad.com. A lot of his examples are C#, which is why I started learning C# instead of VB.NET.
If you don't have it already, make sure you get the SDK for Revit 2014 here: http://images.autodesk.com/adsk/files/Revit2014SDK_RTM0.exe
It has a TON of samples that might help too. Good Luck!

How to set value of a editable combo box in an InternetExplorer window using VBScript?

can anyone please tell me how to set the value of a editable combobox in an IE window using vbscript?
I have set the IE window that i want to use, as an object.
If it was a text box, i have used
ie.document.all("textboxname").value = "textboxvalue"
For radiobutton, i have used
ie.document.all("radiobuttonname")(2).click --- where '2' is index of array (3rd value in array is selected)
For noneditable combobox, i have used
ie.document.all("comboboxname").selectedindex = 2 --- where '2' is index of array
All the above codes work fine, but I am not able to set value for the editable comboboxes in that IE window.
For editable combobox, i tried
ie.document.all("editablecomboboxname").selectedindex = 2
or
ie.document.all("editablecomboboxname").selectedindex.text = "text of any options in the combobox"
or
ie.document.all("editablecomboboxname").selectedindex(2).click
or
ie.document.all("editablecomboboxname").options.selected = 2
But everything leads to this error - "Object doesn't support this property or method: "
Can anyone help me with this? Thanks in advance
Please note I am using only VBscript and no other tools like Visual Studio or QTP.
As per Panayot Karabakalov asked, I have added an example of the code for one such editable combo box below :
<td class="small">
<span id="Curr Car Name" style = "display:none;" class = "small">
Curr Car Name
<font class="asteriskRed" style="font-size:11px" style="display:none;">*</font><br>
<input type="hidden" name='curr_car_name' id='curr_car_name' value='' style='width:180px;height=20px;' >
<script>
getTypeAhead(true,true,'curr_car_name',180,20,'null','AutoCompleteHighlight', 'AutoCompleteBackground','divclass','null',5,20,'curr_car_name_datasrc','','null',0,'setHHChangeIndicator();priorValidations();deleteRowFromAccordion(this);',310,100,'null','');
searchandFill('curr_car_name','',curr_car_name_datasrc);</script>
</span>
<input type="hidden" name="currentcarriernameHdd" id="currentcarriernameHdd" value="null"/>
</td
I saved the webpage(created in Java) as html file and viewed its source code. From there, I have copied and pasted the code for the combobox above. I am not sure if it will be helpful, as I dont have much knowledge of Java.
-- Deepak.
Well, I'll post what I have in mind.
Looking to the error description (Object doesn't support this property or method),
seems to me that your call-by-name...
ie.document.all("editablecomboboxname")
...return different object, i.e. not the element you expected. And as you have not
access to the plain HTML source code, that complicate debuging.
I suspect a naming conflict. What you can do is to see what returns your call-by-name.
MsgBox TypeName(ie.document.all("editablecomboboxname").Type)
But if there some naming conflict, I don't know how you can debug it without
the actual corresponding HTML code block.
# Panayot - Got the answer to my question!!
As you said, I tried with
MsgBox TypeName(ie.document.all("editablecomboboxname").Type)
It returned "String". So I went to a Java colleague of mine and asked him why the combobox is not getting updated even though inputtype is string. After a lot of discussion, he gave me two fields to update for the combobox - a label field to be updated with the string that I wanted in the combobox and another field to be updated with the value corresponding to the string I selected. This is what I used :
ie.document.all("curr_car_name").value = 8001
ie.document.all("_lblcurr_car_name").value = "NO PRIOR CARRIER"
The "curr_car_name" is the editable combobox name, and the "_lblcurr_car_name" is the label for the editable combobox. "NO PRIOR CARRIER" is the text that I wanted the combobox to have, and 8001 is its corresponding value. I got the value 8001 from the javascript that the webpage contained.
This works. :)
Thank you Panayot for all the help.