Getting info from web page between <strong> TAGS - vb.net

So i am trying to get some text from a web page that is located between tags. I have included an image that shows the text i am trying to get.
highlighted text
the code i have currently is as follows although it is gathering other information as well which is not needed.
For Each ele As HtmlElement In WebBrowser1.Document.All
If ele.GetAttribute("className").ToLower.Contains("cwybtn") Then
Dim colourSource As String = ele.GetAttribute("innerText")
'ListBox2.Items.Add(colourSource) 'Adds all .jpg images to the ListBox
MsgBox(colourSource)
End If
Next
Has anyone got any ideas

why don't you try with tagName? you have an element from class name try to get the element from that element as tagName
hope this will help getElementsByTagName("strong")

Ankit
thanks for that! I for got about tagname to be honest, i have now fixed it!
For Each strongTag As HtmlElement In WebBrowser1.Document.GetElementsByTagName("strong")
MsgBox(strongTag.InnerText)
Next

Related

How to open href link in chrome to VBA?

Its my first time using VBA.
Apparently i need it to help me edit the available stocks from various products (gonna need to learn about looping) and that various products left me with different href stocks edit link
Is it possible to click on the href link and open it ?
heres the element
heres the vba script
Sub AutoFill()
Dim obj As New WebDriver
obj.Start "chrome", ""
obj.Get "https://siplah.blibli.com/login/merchant"
obj.FindElementById("txt-email").SendKeys (ThisWorkbook.Sheets("Pass").Range("E20").Value)
obj.FindElementById("txt-password").SendKeys (ThisWorkbook.Sheets("Pass").Range("F20").Value)
obj.FindElementById("btn-login").Click
obj.Wait (500)
obj.FindElementByClass("modal-footer").Click
obj.FindElementById("menu-product").Click
obj.FindElementById("txt-product-name").SendKeys (ThisWorkbook.Sheets("31 CV").Range("E4").Value)
obj.FindElementById("btn-search-product").Click
End Sub
Thank you before!
Combining an attribute = value css selector with ends with operator to target href by the end if its href value, along with adding in the element className should be sufficient
obj.FindElementByCss(".link[href$='Slip']").click
Read about css selectors here: https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors

Is there a way to click on anchor link

Please help me as the anchor tag looks like the below
<a title ="excel" class="activelink"style="Text-Decoration: none; onclick="$find('ReportViewerControl').exportReport('Excelopenxml');" href ="javascript:void(0)" alt="Excel" _selected="true"> Excel</a>
This doesn't have any document id or class.. Any help would be highly appreciated.
I try to check your HTML code and found that it contains the class but it can be possible that many other elements on the page using the same class. If you try to access the link using that class then it can possible that you click the incorrect element on the page.
We can see that the link contains the ' Excel' text. We can try to loop through all the links on the page and try to match the innerHTML to find that specific link.
Example:
'Below is code to loop through anchor tags, find the specific link, and click it.
Set elems = IE.document.getElementsByTagName("a")
For Each elem In elems
If (elem.innerHTML) = " Excel" Then
elem.Click
Exit For
End If
Next elem
Output:
In a similar way, you can also match other attributes from the anchor tag that may also help to click the link.
Note: This code example is for clicking the specific link on a page. It may not help you to automate the file download.
Further, you can try to modify the code example as per your own requirements.

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.

Multiple Lines Webrequest From RichTextBox

Ok so i'm trying to make multiple webrequests, but in a different way.
i'm trying to let my users add the websites on each line of a richtextbox and when they click a button it will run this:
Dim request As WebRequest = WebRequest.Create("Website")
But not for the hole richtextbox, but for every line, so say the richtextbox has all these lines:
google.com
facebook.com
youtube.com
and once they click the button, those sites will be put into the space where it says Website.
If anyone can help me with this, thank you!
Also sorry if this is messy, I don't think there's any other way to present this information!
This could get you started. Textboxes have a Lines property that contains a collection of strings from each line of the textbox (See this MSDN page for reference)
Dim arrUrls() As String = RichTextBox1.Lines
For i As Integer = 0 To UBound(arrUrls)
If Not arrUrls(i).Length=0 Then Dim request As System.Net.WebRequest = System.Net.WebRequest.Create(arrUrls(i))
Next

Vb.net click link by looking for String!

I am working on a vb.net program, I want to click a hyperlink on a page, the source look like this:
messages for Today, 2010-10-19
I want to check it everyday too!
I tried to click it with the following methods(Both couldn't click the link!):
Dim theElementCollection As HtmlElementCollection
Dim ctrlIdentity As String
theElementCollection = WebBrowser1.Document.GetElementsByTagName("a")
For Each curElement As HtmlElement In theElementCollection
ctrlIdentity = curElement.GetAttribute("innerText").ToString
If ctrlIdentity = Today.Date.ToString(Today.Date.ToString("dd")) Then
curElement.InvokeMember("click")
End If
Next
and I tried this code too:
If Me.WebBrowser1.Document.Links(i).InnerHtml.Contains(Today.Date.ToString("dd")) Then
Me.WebBrowser1.Document.Links(i).InvokeMember("Click")
End If
Next
Any help would be appreciated! Thanks!
I've found that the best way to click links in a WebBrowser is using javascript. Try something like this:
WebBrowser1.Navigate("javascript:function%20x(){document.getElementById('foo').click()}x()")
You'll need to rewrite your above code in javascript but that's a piece of cake. You can test your javascript by copy-pasting it directly into the browser's location bar. This is also a reliable way to fill out forms.
Caveats:
Notice how the work that I want to do is wrapped in a function. This is needed if you want the javascript to do multiple statements. Wrap in a function and then invoke the function.
You can't navigate to a URL more than around 500 characters. (The limit isn't exactly 512 but it's close.) There's no warning, either, so keep it in mind.
Make sure you wait until the page is loaded. The ReadyState = Complete and IsBusy = False.
Clicking like this doesn't always generate the usual events that you get when you click a link.
"%20" is hex for space. I don't recall if this was strictly necessary in my code. Try it both ways.