Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Trying to get Active elements from default web browser
without using form layout + Web Browser Control.
and post the username + password.

What I have tried:

VB



Dim webBrowser1 As Object = New WebBrowser
webBrowser1 = Process.Start(MemSite(CurrCell), ProcessWindowStyle.Maximized)
Dim HtmlDoc As HtmlDocument = webBrowser1.Document
Dim htmlElem As HtmlElement = HtmlDoc.All.Item(0)
If htmlElem.TagName = "HTML" Then

End If
Posted
Updated 24-Oct-18 23:48pm

VB


Quote:

Private Sub NavWeb()
Browser()
'Dim driver As New InternetExplorerDriver
'Dim driver As New ChromeDriver
Dim driver As New EdgeDriver
'Dim driver As New SafariDriver
driver.Navigate.GoToUrl(MemSite(CurrCell))
Dim HtmlElem As IWebElement
HtmlElem = GetWebElement(driver, By.TagName("html"), 20)
If HtmlElem.TagName = "html" Then
MsgBox("Fond HTML page in " & "Browser: " & Browser())
End If
End Sub

Private Overloads Function GetWebElement(ByVal webDriver As IWebDriver, ByVal definition As By, ByVal timeoutSeconds As Integer) As IWebElement
Dim wait As New WebDriverWait(webDriver, TimeSpan.FromSeconds(timeoutSeconds))
wait.Until(Function(d)
Return d.FindElement(definition).Enabled And d.FindElement(definition).Displayed
End Function)
Return webDriver.FindElement(definition)
End Function

Function Browser()
Const HKEY_CURRENT_USER = &H80000001
Const strKeyPath = "Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice"
Const strValueName = "Progid"
Dim strValue, objRegistry, i
strValue = Nothing
Dim blist(6, 1) 'Browser list:
blist(0, 0) = "Intermet Explorer" : blist(0, 1) = "ie"
blist(1, 0) = "Edge" : blist(1, 1) = "appxq0fevzme2pys62n3e0fbqa7peapykr8v"
blist(2, 0) = "Firefox" : blist(2, 1) = "firefox"
blist(3, 0) = "Chrome" : blist(3, 1) = "chrome"
blist(4, 0) = "Safari" : blist(4, 1) = "safari"
blist(5, 0) = "Avant" : blist(5, 1) = "browserexeurl"
blist(6, 0) = "Opera" : blist(6, 1) = "opera"
objRegistry = GetObject("winmgmts:\\.\root\default:StdRegProv")
objRegistry.GetStringValue(HKEY_CURRENT_USER, strKeyPath, strValueName, strValue)
If strValue Is Nothing Then
Browser = "Intermet Explorer" : Exit Function
Else
For i = 0 To UBound(blist, 1)
If InStr(1, strValue, blist(i, 1), vbTextCompare) Then Browser = blist(i, 0) : Exit Function
Next
End If
Browser = "Unknown web browser" '(signature: '" & strValue & "')"
End Function
 
Share this answer
 
The only way to do that is Selenium. You were told that two days ago, here[^].

Again, what makes you think VB.NET isn't supported by Selenium?
 
Share this answer
 
Comments
Alex Steinmetz 17-Oct-18 13:34pm    
Hi Dave
I am not sure what to download from Selenium.
Can you be so kind and help.
Dave Kreskowiak 17-Oct-18 14:27pm    
You don't have to download anything really. In your project in Visual Studio, go the Tools menu and click NuGet Package Manager --> Package Manager Console.

In the Package Manager Console, type "Install-Package Selenium.WebDriver" and hit ENTER.

When that completes, type "Install-Package Selenium.WebDriver.ChromeDriver", then "Install-Package Selenium.WebDriver.IEDriver".

There is a FireFox driver in the package "Selenium.Firefox.WebDriver", but that one wasn't written by the Selenium project.

Alex Steinmetz 18-Oct-18 7:07am    
Hi Dave.
Thanks for your guideness.
I have installed the drives + added to project references, imported namespaces.

But I don't have the minimum idea how to use it, to solve above question.

I have tried Selenium site doc. + Selenium user group, but noting.

a lot of questions with verey few answers.

Are you ready to spend a little more time and helping me and others to solve

above.

I will be very great full,
Dave Kreskowiak 18-Oct-18 10:38am    
I don't get a lot of time to do this. I've got my own work I have to get through.

This is just a quick example of creating a browser instance and getting it to navigate to a URL:
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Chrome
Imports OpenQA.Selenium.Support.UI

Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim driver As New ChromeDriver
        driver.Navigate.GoToUrl("http://www.google.com")

        Dim searchBox As IWebElement
        searchBox = GetWebElement(driver, By.Name("q"), 10)
        searchBox.SendKeys("2001 something wonderful")
        searchBox.SendKeys(Keys.Enter)
    End Sub

    Private Overloads Function GetWebElement(ByVal webDriver As IWebDriver, ByVal definition As By, ByVal timeoutSeconds As Integer) As IWebElement
        Dim wait As New WebDriverWait(webDriver, TimeSpan.FromSeconds(timeoutSeconds))

        wait.Until(Function(d)
                       Return d.FindElement(definition).Enabled And d.FindElement(definition).Displayed
                   End Function)

        Return webDriver.FindElement(definition)
    End Function
End Class
Alex Steinmetz 25-Oct-18 5:37am    
After checking & testing for a few days
I can state very clearly that the only possible & simple answer
to this problem is:
Script Show default browser (updated for Win10)[^] by Jorgen Bigom
plus Selenium Project.
THANKS to Dave & duDE help and guideness.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900