How to Implement Custom Selenium WebElement FindElement - vb.net

I want to create a custom WebElement from IWebElement and then implement FindElement to locate an element in my internal list of elements in m_Elements:
I have this snippet so far:
Imports OpenQA.Selenium
Imports OpenQA.Selenium.By
Imports System.Collections.ObjectModel
Imports System.Drawing
Imports System.Text.RegularExpressions
Public Class MyWebElement
Implements IWebElement
Private m_Elements As New List(Of MyWebElement)
Public Function FindElement(byObj As By) As IWebElement Implements ISearchContext.FindElement
'
End Function
If I look at byObj in Visual Studio I see:
Equals, FindElement, FindElements, GetHasCode, GetType, ToString.
If I look at byObj in the debugger I see:
Description, FindElementMethod, and FindElementsMethod
How do I determine what By class was used by the caller? By.Id, By.TagName, etc.
How do I get the SearchContext?

Related

I'm trying to capture a webcam image using the emgucv library

This code is giving an error : type capture not defined
Imports Emgu.Cv
Imports Emgu.Cv.UI
Imports Emgu.Cv.Structure
Public class Form 1
Dim webcam as New capture
I was expecting it to create a new capture object

VB .Net BC30491: Expression does not produce a value

This is my part of code:
Imports System
Imports System.IO
Imports System.Threading.Tasks
Imports Proxies
Imports Services
Imports Settings
Imports Microsoft.Extensions.Configuration
Imports Microsoft.Extensions.DependencyInjection
Imports Microsoft.Extensions.Logging
Public Class Program
Private Shared _serviceProvider As IServiceProvider
Private Shared _configuration As IConfigurationRoot
Private Shared _logger As ILogger
Private Shared Sub SetupConfiguration(ByVal environment As String)
_configuration = New ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()).AddJsonFile($"{environment}.settings.json", [optional]:=True, reloadOnChange:=True).AddEnvironmentVariables().Build()
End Sub
Private Shared Sub SetupServiceProvider()
Dim serviceCollection As IServiceCollection = New ServiceCollection()
serviceCollection.AddSingleton(_configuration)
Program.ConfigureServices(serviceCollection)
_serviceProvider = serviceCollection.BuildServiceProvider()
_logger = _serviceProvider.GetRequiredService(Of ILogger(Of Program))()
End Sub
Private Shared Sub ConfigureServices(ByVal services As IServiceCollection)
services.AddLogging(Function(opt) opt.AddConsole())
services.AddMemoryCache()
services.Configure(Of AuthorizationSettings)(Function(s) _configuration.GetSection(NameOf(AuthorizationSettings)).Bind(s))
services.Configure(Of ServicesSettings)(Function(s) _configuration.GetSection(NameOf(ServicesSettings)).Bind(s))
services.AddSingleton(Of ITokenService, TokenCacheService)()
services.AddSingleton(Of IIdentityServiceProxy, IdentityServiceProxy)()
services.AddSingleton(Of IIdentityImportService, CsvIdentityImportService)()
End Sub
End Class
I got the error in these two lines and do not let me compile:
services.Configure(Of AuthorizationSettings)(Function(s) _configuration.GetSection(NameOf(AuthorizationSettings)).Bind(s))
services.Configure(Of ServicesSettings)(Function(s) _configuration.GetSection(NameOf(ServicesSettings)).Bind(s))
The error I got is this:
BC30491: Expression does not produce a value
Any ideas on how to fix it?. I use this code to connect to an API using OAuth 2.0 and JSON Web Token (JWT) AuthorizationSettings and ServiceSettings are two classes which return configuration. This code was converted from a C# code

How to upload file with Asp.net Web Api project?

i have a web API project to be consumed from mobile applications and i was trying to make a file upload controller. there are few resources in C# and i don't find anything useful for VB.NET.
i tried this code below converting from c# to VB.NET, but says "Move is not a member of MultiPartFileData".
Imports System
Imports System.Collections.Generic
Imports System.IO
Imports System.Linq
Imports System.Net
Imports System.Net.Http
Imports System.Threading.Tasks
Imports System.Web
Imports System.Web.Http
Namespace HelloWorld.Controller
Public Class FileUploadingController
Inherits ApiController
<HttpPost>
<Route("api/FileUploading/UploadFile")>
Public Async Function UploadFile() As Task(Of String)
Dim ctx = HttpContext.Current
Dim root = ctx.Server.MapPath("~/App_Data")
Dim provider = New MultipartFormDataStreamProvider(root)
Try
Await Request.Content.ReadAsMultipartAsync(provider)
For Each file In provider.FileData
Dim name = file.Headers.ContentDisposition.FileName
name = name.Trim(""""c)
Dim localFileName = file.LocalFileName
Dim filePath = Path.Combine(root, name)
File.Move(localFileName, filePath)
Next
Catch e As Exception
Return $"Error: {e.Message}"
End Try
Return "File uploaded!"
End Function
End Class
End Namespace
That error message means the compiler think that you are trying to call a method from the MultiPartFileData class. The variable of type MultiPartFileData is the one called file (notice the lowercase) initialized in the For Each loop.
Instead you want to call the Move method from the System.IO.File class (notice the uppercase).
VB.NET services (always running in background looking to catch errors while you type) is case insensitive so, for it, the two names are the same and here arises the error emitted when you code that line.
The best solution is to avoid names like file for your variables when you plan to use the class System.IO.File. Otherwise you could simply add the full qualified method's name in this way
System.IO.File.Move(localFileName, filePath)

convert SOAP to REST and return many records from a function

Convert working SOAP WCF to REST and still use Function that reads and returns the values I need.
ActiveCallSevice reads entity to return several records using SOAP in VB. How can I code it to return all the records when changing to REST? I have tried many different versions of the uriTemplate but nothing is working. I basically should read a view and return the data without getting any parms from uri. I used good example from here, but that one is manually coding value returned from looping and I have a Function that reads and returns the values I need.
My IActiveCalls.vb code current on WebGet line - error states - Constant expression is required. C:\inetpub\VS2013\wcfWazeP1\IActiveCalls.vb 10 13 WcfWazeP1.
Public Interface IActiveCalls
Property UriTemplate As String
<WebGet(UriTemplate = "Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents)")>
<OperationContract()>
Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents)
Implements IActiveCalls
Dim dbP1RDW As New ReportingDWEntities
Public Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents) Implements IActiveCalls.GetWazeCalls
Return dbP1RDW.DIT_CurrentSOTrafficIncidents.OrderBy(Function(o) o.IncidentDate).ToList()
End Function
<DataContract()>
Public Class ActiveCalls
End Class
My ActiveCalls.vb code on Implement line – error states -Class 'ActiveCallsService' must implement 'Property UriTemplate As String' for interface 'IActiveCalls'. Implementing property must have matching 'ReadOnly' or 'WriteOnly' specifiers. C:\inetpub\VS2013\wcfWazeP1\ActiveCalls.vb 9 16 WcfWazeP1.
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.Text
Public Class ActiveCallsService
Implements IActiveCalls
Dim dbP1RDW As New ReportingDWEntities
Public Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents) Implements IActiveCalls.GetWazeCalls
Return dbP1RDW.DIT_CurrentSOTrafficIncidents.OrderBy(Function(o) o.IncidentDate).ToList()
End Function
End Class
12/07/2017 Thanks GMan80013, After changes. Still have errors that prevent it from running. I tried several placements of the UriTemplate declaration with no luck. How important is the name of the UriTemplate? Could I call it anything, or should it reference the ActiveCallsService? Sorry to be so uninformed.
ActiveCalls.vb two errors
1- Field or property 'UriTemplate' is not found. C:\inetpub\VS2013\wcfWazeP1\IActiveCalls.vbWcfWazeP1
2- 'WebGetAttribute' cannot be used as an attribute because it does not inherit from 'System.Attribute'. C:\inetpub\VS2013\wcfWazeP1\IActiveCalls.vb
Public Interface IActiveCalls
Property UriTemplate As String
<WebGet(UriTemplate:="currentSOTrafficeIncidents")>
<OperationContract()>
Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents)
End Interface
ActiveCalls.vb – I added the Public Property UriTemplate and no errors here
Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Runtime.Serialization
Imports System.ServiceModel
Imports System.Text
Public Class ActiveCallsService
Implements IActiveCalls
Dim dbP1RDW As New ReportingDWEntities
Public Property UriTemplate As String Implements IActiveCalls.UriTemplate
Public Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents)
Implements IActiveCalls.GetWazeCalls
Return dbP1RDW.DIT_CurrentSOTrafficIncidents.OrderBy(Function(o)
o.IncidentDate).ToList()
End Function
End Class
1) The URI Template value is meant to represent the part of the URL after the host name. If your site address is http://www.myhouse.com/ and you want clients to get all records with this address http://www.myhouse.com/currentSOTrafficIncidents Then "currentSOTrafficIncidents" is the URI Template. Also, possibly the cause of the error, be sure after UriTemplate you have := not just =. This is required in vb any time you are specifying the parameter name.
<WebGet(UriTemplate:= "currentSOTrafficIncidents")>
<OperationContract()>
Function GetWazeCalls() As List(Of DIT_CurrentSOTrafficIncidents)
2) In your interface you declared Property UriTemplate As String and this public property is missing from the ActiveCalls.vb class. I don't think you need this, however and could remove it from the IActiveCalls class. If you really want to keep it there, correct the error by adding this to ActiveCalls.vb.
Public Property UriTemplate As String Implements IActiveCalls.UriTemplate

Is there an advantage to using nested namespaces instead of Partial Public NotInheritable Classes

It seems advantages of using Partial NotInheritable Class is that one can declare/implement shared methods in them.
Here is a code sample, to help visualize the matter.
Namespace MyNamespace.Utility
' Cannot Declare Shared Function
Public NotInheritable Class Document
' Can Declare Shared Function
End Class
End Namespace
This is opposed to
Namespace MyNamespace
Partial Public NotInheritable Class Utility
' Can Declare Shared Function
Partial Public NotInheritable Class Document
' Can Declare Shared Function
End Class
End Class
End Namespace
Utility should be a namespace because it is acting as a logical grouping.
Microsoft .NET Framework Nested Types Guidelines
I don't follow your claim that an advantage of a sealed class is that you can define static methods, any class can do that.