How to check all the links dynamically? - dynamic

The following thing I have to do using VBScript in QTP 10/11:
The VBScript opens one login page. After the login it counts the number of links in that page and then prints all the links. Afterwards it opens every link one by one.
I am having issues with finding all the dynamic links.

You can get all the links on a page by using the Page's (or Frame's) ChildObject method.
Set desc = Description.Create()
desc("html tag").Value = "a"
Set links = Browser("B").Page("P").ChildObjects(desc)
For i = 0 to links.Count - 1
Print links(i).GetRoProperty("inner_text") & " => " & links(i).GetRoProperty("href")
Next
As for clicking them, that's a bit more complicated since after clicking a link you cause a navigation that invalidates the links object, you should either perform the ChildObjects each time (while keeping track of the index) or open the links in a different browser/tab.

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

How can I redirect to the same page multiple times with a different query string?

I have a page that contains a table with a list of data and an icon (on each row) which redirects the user to a new aspx page with a queryString and does some custom logic to then download the file. The user has asked that we make a "download all" button so they don't have to go through and manually click every icon in every row.
My code is close, I feel, but it will hang after the first file is downloaded and will never progress further.
Here is the code I have so far
Protected Sub ibDownloadAll_Click(sender As Object, e As ImageClickEventArgs)
'Get Parameters
'Run stored procedure to get the query string we're going to use
'Fill DataSet
For Each myItem As DataRow In ds.Tables(0).Rows
Response.Redirect("redirectPage?ID=" &myItem.Item("ID")) 'Gets stuck after here
Next
End Sub
I realized if I added the second parameter (Indicates whether execution of the
current page should terminate)
Response.Redirect("redirectPage?ID=" &myItem.Item("ID"), False)
Then it would make it to the end of the function, running through the loop as expected, but then only outputting/downloading the last file.
Is there something I'm missing or an alternative that can be used to effectively redirect multiple times? Unfortunately with the framework I'm using I'm not able to use Response.Write and put custom scripts in that way, nor can I really change the page that we are redirecting to.
You can't redirect to multiple pages (a redirect close the request) and you also can't send multiple files. Your only option would be to have a request that zip all the files together. You can do this with System.IO.Compression.ZipArchive. You don't need to save the zip on disk, you could just send the memory stream.

Can we Traverse on another page when executing foreach loop?

There is Table on the page, I do need to retrieve information row by row. That is handle by for-each. Execution on same page for retrieving information is working fine.
But, Can we handle Detail page of particular Row ? Here "Test 1" has its own detail page. There are some operation which need to handle on detail page. How can we manage it and get back to actual execution.
As of now I am dealing it with for-each loop, and getting StaleElementReferenceException which is correct as webElement lost its actual ListElement<WebElement>
List<WebElement> findList = driver.findElements(By.xpath("//a[#class='*****']));
for (WebElement webElement : findList) {
...
//detail page is access by clicking webElement
webElement.click();
findList = driver.findElements(By.xpath("//a[#class='*****']));
}
If there is any way, Please suggest. Thanks.
You can do something like this :
List<WebElement> findList = driver.findElements(By.xpath("//a[#class='*****']));
for(int i = 1 ; i<=findList.size() ; i++){
driver.findElement(By.xpath("(//a[#class='***'])[" + i + "]")).click();
// extract some data from next page which is invoked by clicking on Test1 hyperlink.
}
in this way every time you are looking for //a[#class='***'][i] web element i , starting from 1 and till the end point.
P.S : You need to check this in devtool //a[#class='***'][1], whether it indicates the Test1 hyperlink or not.
Hope this helps.
Try to collect urls to detail pages of all and then open them.
There are two scenarios i can think of :
Clicking the link e.g. Test1 opens a new tab :
In this case you can just switch to new tab inside your loop , finish your operation on this tab and finally close the second tab / switch to first tab before continuing with your next iteartion. This should also not cause StaleElementException.
Clicking the link e.g. Test1 redirects to some other url in same tab :
For each iteration of loop, click on target link , perform some operation on new page.Before you continue with next iteration , Navigate to page containing your table again and lookup all the row elements again. Now , for next iteration you won't get StaleElementException. You will want to use the for loop so that you can maintain the index outside instead of a foreach variant.
findList = driver.findElements(By.xpath("//a[#class='*****']))
I would recommend the first option since that would be more clean and you can perform a shift + click on your link e.g. Test1 to force it open in a new tab instead of redirecting in same page. You can perform a shift + click using "Actions api" available in Selenium.

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

In Microsoft Publisher VBA, how to access selected page?

In Publisher, not VBA, I use the navigation pane to select page 5. Now, the work I do manually will apply to page 5. However, now I want to run a macro I wrote which will import, resize, label, etc. a batch of images. How do I make my macro recognize that I want those images imported onto page 5 (my current working page)?
I wrote my macro hardwired to page 2 (because I couldn't answer the above question):
set pg = activedocument.pages(2)
I envisioned something like (but this doesn't work, of course):
set pg = activedocument.selected.page
Similarly, after my macro runs, and it adds three new pages, I want the selected/active page to be the last page I added (e.g., page 9). How to do that? Again, I envisioned something like:
activedocument.pages(9).select
Much thanks.
The property that you found (helping me out, so thanks!) is for both getting and setting, but the trick is that you have to set it to a page, rather than trying to set it to a PageIndex ("ActivePage = 2")
ActiveDocument.ActiveView.ActivePage = yourPage;
For instance, you could go to the next page with:
pubApp.ActiveDocument.ActiveView.ActivePage = pubApp.ActiveDocument.Pages[pubApp.ActiveDocument.ActiveView.ActivePage.PageIndex+1];
...Just realised that you're asking about VBA rather than C#, so here are some VBA examples just for you:
GoToNextPage()
ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(ActiveDocument.ActiveView.ActivePage.PageIndex + 1)
End Sub
GoToPageTwo()
ActiveDocument.ActiveView.ActivePage = ActiveDocument.Pages(2)
End Sub
Question 1 is answered:
Set p = ActiveDocument.ActiveView.ActivePage
Question 2 remains:
How do I use vba to make active a new particular page?
(i.e., i could use VBA such that the above would return to me a different page for "p"?)
For a shape, I can say: "my_shape.select"; how do I do that for a page?