Please help to solve the following code - vb.net-2010

Iam Trying to capture page name in the url(localhost/fca/htp/home.aspx). This works for the first time. when page is loaded first time indexofdot takes the value 4 which is home. But when page gets refreshed or when we come back to home page again after visiting other pages it is taking the value 5 which is error.I tried page.ispostback to skip when refreshed but it is not working.
Thank you in advance
If String.IsNullOrEmpty(PageName) Then 'Probably the home page
Dim PathComponents As String() = Request.FilePath.Split("/")
Dim indexOfDot As Integer = PathComponents(PathComponents.Length - 1).IndexOf(".")
If indexOfDot > -1 Then
PageName = PathComponents(PathComponents.Length - 1).Remove(indexOfDot)
End If
End If

Put your code in the page load method, or if you need to execute the function in page init, put some value in an hidden field at the first load, so that you can easily test the value of the hidden field in the Request.Form

Related

WebBrowser.DocumentText Not Updating

I am loading a web page into webbrowser control and after waiting for the document to load, I am reading in the .documenttext to retrieve various bits of data.
I then want to test if the data on the web page has changed (it's a dynamic update) and if so, I retrieve the updated data.
The problem is that .document.text is not updating, either after a dynamic update to the page or if I physically navigate within the browser control to another page.
When I loop through all elements using '.getelementsbytagname' I get the up to date web page data, but obviously want to avoid this if the data hasn't changed. So '.document' updates but '.documenttext' doesn't.
So the '.documenttext' doesn't get updated when the web page changes. Is there a way to force this update? Or a better/simpler way to check for a page update?
.refresh() does work, but I don't want to be reloading the document when it's already up to date.
Dim pp = Uni.wbUni.DocumentText
If pp = GlobalVariables.unistr Then
Console.WriteLine("no change" & Now())
Exit Sub
End If
Console.WriteLine("change" & Now())
GlobalVariables.unistr = Uni.wbUni.DocumentText
So from the above pp never actually updates
Dim pp = Uni.wbUni.Document.Body.InnerText

VBA automation can't get innerText (innerHTML, value)

So, i've gotten innertext many times. This time, it's simply not working. Tried many alternatives.
First of All
I'm using Selenium on VBA to use chromedriver.
The source website is "[http://www.fazenda.df.gov.br/area.cfm?id_area=1536]" This website operates on a Iframe. After half an hour trying to get the inner text from it, i figured that the link in its code works just as fine: "[http://publica.agnet.fazenda.df.gov.br/FichaImovel/#/FichaCadastral]". This last one seems to operate on someting call "Angular".
The menu with the innertext i required is a dropdown one. As a dummy value, you can use 50868748. The dropdown text that it generates is composed by 15 lines and one table. The info that i need is on the 15th line, "Nome do Responsável", or in the column 2 line 2 on the table.
I managed to place the code and generate the dropdown list, but i can't manage to get the inner text.
Here is my code:
Dim iptu As String
Dim driver As New ChromeDriver
With driver
.Start
iptu = 50868748 'dummy
.Get "http://publica.agnet.fazenda.df.gov.br/FichaImovel/#/FichaCadastral"
.FindElementById("inscricaoImovel").Clear
.FindElementById("inscricaoImovel").SendKeys iptu
.FindElementsById("btnCadastro")(2).Click
.Wait (300)
'until here, everything works fine
Dim label As Object
Dim name As String
Set label = .FindElementsByClass("ng-binding")(91)
'as you can see, i end up using this class(91) to get the value on the table, but i can get from the 15th line too
name = label.getAttribute("innerText") 'Error is here
'i've tried .innerText, .innerHTML and others. The error is always "object does not accept property or method" Error 438.
end with
The chrome driver is up to date. Also, the page source does not cointain the info i need.
Anyone can help me out?
To get InnerText of the element, You need to call Text method
Set label = .FindElementsByClass("ng-binding")(91)
name = label.Text
To get inner Html,
name = label.Attribute("innerHTML")
Sometimes I have found that I have to execute javascript to get what I'm after. You can try
name=driver.ExecuteScript("document.getElementsByClassName('ng-binding')[91].innerText;")

Unable to get the Query String value

Whenever I'm hitting this URL getting vToken is nothing. Please assist
Dim vHDR As String = Nothing
If Request.IsLocal Then
Dim vToken = Request.QueryString("approvalToken")
If Not vToken Is Nothing Then
Dim vUser = Helper.ValidateToken(vToken)
If Not vUser Is Nothing Then
vHDR = vUser
End If
End If
End If
URL:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ
In a URL, everything beginning with the hash sign (#) is called the Fragment Identifier. The fragment identifier section is the last section of the URL and comes after the url arguments.
So for this url from the question:
http://localhost:56979/#/modules/Review?ID=20582&approvalToken=SIsJ3swuGjpPidOvWPSzuqfcTJH8IywIlVVEnkmIQU6yE93PUQ
there is no query string. The section that looks like a query string was pre-empted to be part of a very long fragment identifier. Even the /modules/Review section that looks like part of the Path is actually part of the fragment.
I suspect somewhere in your base/index page you have a link with a blank href value, which is sometimes expressed with a single hash (#). You click that link, which puts the hash sign into the url:
http://localhost:56979/#
After clicking this link, you then redirect, click a new link, or do some other action that appends the relative url /modules/Review (which may already include the query string) to your current location. But now you have the hash sign as part of that existing location, and so you end up with the url in your question, which doesn't mean what you want it to mean.
I'd have to see a lot more code to tell you exactly how to fix this, but in the context of vb.net (asp.net), if this code runs on the server you probably want to change /modules/Review to ~/modules/Review. If this is done in javascript, I'd need to know more about your page.

PCOMM gettext is pulling invisible information

I've had a randomly recurring issue where I can use gettext to pull information just fine from a page on a PCOMM (IBM Personal Communicator) screen, then when I go to the next screen it will pull that SAME information, despite appearing visually blank.
I can't paste screenshots for InfoSec reasons... But here's the gist:
Dim ps As New AutPS
Dim oia As New AutOIA
Page 1: ps.GetText(15,31,7) = 1800.00 (I can see this value on the screen.)
Go to next page, wait for oia.InputInhibited = 0 And ps.Ready
Page 2: ps.GetText(15,31,7) = 1800.00 (Screen in this position appears blank.)
This issue is not isolated, and is repeatable with a specific account number.
Found a solution!
The key lies with using the ps.autECLFieldList. This object can detect when a given field (located using FindFieldByRowCol) is displayed or not, so when used in tandem with our getText, we can make sure that we're only retrieving information from a visible field.
Dim fl As Object = ps.autECLFieldList
fl.refresh() 'Good practice to make sure the Field List is up to date
If fl.FindFieldByRowCol(15, 31).display Then
Amount = ps.GetText(15, 31, 7)
End If

How to use a session variable of one page to initialize another page's global variable in vb.net?

I have 2 web pages. In the first webpage I have a text box which takes an user input.The number of controls rendered in the second page is based on the user input in the first page.
I am storing the user input from the first page as a session variable
Session("NoOfControlsToGenerate") = TextBox1.Text
Now, I wish to use this session variable in the next page for initializing a global variable and what I tried to do is
Dim num_Invitees As Integer = CType(Session("NoOfControlsToGenerate"), Integer)
But this gives me a NullReferenceException.
Can someone please suggest me what exactly I should be doing in order to use the session variable to initialize a global variable and also why the session variable's value is null while using outside a function but works fine when used inside a function?Thanks in advance
Thank You
ASP.net makes passing such parameters deceptively easy. If you're posting back to the same page, you'll be able to simply read the value of the textbox, which will persist across the postback by default.
If you're posting to another page, you can use
CType(Page.PreviousPage.FindControl("YourTextBoxID"), TextBox).Text