How to wait for page load for any browser - hp-uft

During test run, multiple tabs get opened in chrome. As it is opening the new tabs, I would like UFT to wait until complete page loads. I am trying to make it a standard wait without waiting for a specific object.
For example, during run chrome opened, launched URL, click a link, new tab opened, now for the new page to load. Then click a link from 2nd tab and wait for the 3rd page to be loaded.
How can I force UFT to wait for the last page loaded assuming there are multiple tabs?

This will wait till all page is downloaded.
Browser().Page().Sync
This will wait for particular object
Browser().Page().Object().Waitproperty
If you want for property of object(s) to change, loop it, like
Do Until WaitProperty = Argument
print "Wait. Progress "&Progress
wait 3 'wait 3 seconds
Progress = Progress+"." 'add a period to show progress
Set ObjColl = MyBrowser.ChildObjects(WObj)
WaitProperty = cstr(ObjColl(t).GetROProperty(Arg4)) 'get the object property
Loop
To loop through all pages in a browser:
'Get Pages count:
Set browserObject = Description.Create
browserObject("micclass").Value = "Browser"
GetBrowserCount = Desktop.ChildObjects(browserObject).Count
'loop and sync (or any other methods):
for i = 0 to GetBrowserCount-1
browser().page("micclass:=Page","CreationTime:="&i,"Title:=.*").Sync
next

You can use .Sync for each browser opened also you can use .WaitProperty "visible","true" in order to wait for a property of an object displayed.

Related

How do I wait for data to load before it renders the page when clicked onto a link in Cypress?

The app was built in a way that you can't go straight to a specified url. So I can't do cy.visit(#specifiedURL)... So I need to do this:
cy.get('btn')
.click()
.then(() => {
cy.wait(#alias);
});
So when clicked onto that button it redirects me to a new page of the app but I need the data to load before rendering the page...
You could wait for an element on the next page to be visible to ensure the page has loaded properly if you want.
Cypress waits for any command(click() or type() etc...) for 4 secs by default and click() method will be invoked irrespective of page is loaded or not after 4 secs.
So In order to wait for page to fully load, you need to tell cypress to wait how long in cypress.json file and you can specify with "pageLoadTimeout": 10000 in cypress.json
{
"integrationFolder": "cypress/integration",
"defaultCommandTimeout": 10000,
"pageLoadTimeout": 10000
}
Change to something like above and then, first cypress get method will not invoke until 10 secs of pageLoadTimeout and then cypress makes query for get method. If you have specific requirement of timeouts, just read the documentation here https://docs.cypress.io/guides/references/configuration.html#Timeouts

Wait until a 'Click' on a WebButton of type submit is completely finished

I am trying to automate JIRA post configuration using VBScript. After database configuration page when I click on next button it takes several minutes to go on next URL. I want my VBScript to wait until this next button process is finished and then go to next URL.
Right now, after the next button I have made the script sleep till 2 minutes and then navigated it to next page.
But I need some replacement to WScript.Sleep in my code. Since this time will differ on every machine.
Following is the code I'm using right now:
IE.Document.getElementById("jira-setup-database-submit").Click
WScript.Sleep 120000
If (fso.FileExists("C:\Program Files\Atlassian\Application Data\JIRA\dbconfig.xml")) Then
Call URL3
Else
ie.Visible = 1
MsgBox("Please enter valid Database Credential ")
End If
This will cause VBA to effectively pause until the browser returns that it's ready and has finished loading.
Do While (IE.Busy Or IE.READYSTATE <> 4)
DoEvents
Loop

Need VBScript Code to toggle between two Webpages to copy content from one page and paste to another webpage

I am need of VBScript code to paste the content from one IE Explorer WebPage window to another IE Explorer WebPage window.
Currently i know the Process ID.
However I am not able to switch from one webpage to another. Or you can say my control does not move from one page to another.
#shellbye
Function Bmc(abc,xyz)
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("// SOME APLLICATION") ' #opened the Web applcation
'# LOGGED INTO THE APPLCATION SUCCESSFULLY suing the VBScript
For i = 0 To objIE.Document.links.Length - 1
if objIE.Document.links(i).innerText ="Create a New Case" Then
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.links(i).click '## THIS OPENS A NEW Window as link is an URL
Exit For
End If
End Function
In above, I am able to Open the new window after clicking the link i.e. at Step ##
Now I want to copy the content abc and xyz passed in the function Bmc(abc,xyz) to New Window opened through this.
However I am unable to move or us can say switch control to new window.

Ruby Selenium Webdriver - Need to wait / sleep while page redirects (refreshes)

I'm using the Ruby selenium-webdriver gem to create a web-crawling/scraping script. The page that I'm scraping is loaded via AJAX and displays information for a certain account. If you select a second account number on a dropdown menu, the page redirects very briefly to another URL and back to the original URL, just with different information loaded via AJAX. I want to be able to scrape info for both the account numbers listed on the dropdown options. The problem is that Selenium performs the scrape faster than the page can redirect/reload on the dropdown click, so I don't end up getting the second account's information.
def crawl_page
browser = Selenium::WebDriver.for :firefox
browser.manage.timeouts.implicit_wait = 10 # seconds
browser.navigate.to 'http://www.foobar.com'
account_dropdown = Selenium::WebDriver::Support::Select.new(browser.find_element(:id, 'account'))
account_dropdown.options.each do |option|
option.click
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
# this wait is not working because option is selected before redirect/refresh:
wait.until { option.selected? }
html = browser.page_source
scrape_page(html)
end
browser.quit
end
I've tried putting a sleep(3) on the line after the click, but get the following error message:
[remote server] resource://fxdriver/modules/web_element_cache.js:8180:in `fxdriver.cache.getElementAt': Element not found in the cache - perhaps the page has changed since it was looked up (Selenium::WebDriver::Error::StaleElementReferenceError)
I've also tried using Selenium's explicit wait code, but the ids of the elements appear to dynamically change on the updated page so something like:
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until { browser.find_element(:id, 'titlexyz').displayed? }
results in an error message that says it's timed out and can't find the element:
~lib/selenium/webdriver/common/wait.rb:57:in `until': timed out after 10 seconds (Unable to locate element: {"method":"id","selector":"titlexyz"}) (Selenium::WebDriver::Error::TimeOutError)
Is there some way to get it to sleep or wait without having to look for a specific element on the page?
OK, so I finally figured it out thanks to SiKing's answer. The trick was to count the number of options for the dropdown menu, and put that into a .times loop. Then on each iteration, I instantiated a new Selenium object for the dropdown menu, found the correct option number and clicked it. I also put the script to sleep for 5 seconds to give it a chance to do the reload/redirect.
def crawl_page
browser = Selenium::WebDriver.for :firefox
browser.navigate.to 'http://www.foobar.com'
account_dropdown = Selenium::WebDriver::Support::Select.new(browser.find_element(:id, 'account'))
count = account_dropdown.options.count
count.times do |option_num|
account_dropdown = Selenium::WebDriver::Support::Select.new(browser.find_element(:id, 'account'))
account_dropdown.options[option_num].click
sleep 5
html = browser.page_source
scrape_page(html)
end
browser.quit
end
I do not do ruby, so I cannot help you with the ruby syntax.
Every time a page reloads (in your code every time you do option.click), all WebElements (your account_dropdown.find_elements(:css, 'option')) that you have are no longer valid! You will have to base your loop on something else - perhaps the count of the items in the pulldown - and find each of the elements you want to interact with inside the loop!

wp7 open another web browser control inside web broser control

I have web browser control which contains many links and data. All these data are coming from web service.
Now i want open another web browser control when i click on first web broser link.
so how it can be done?
my first web broser code is :
webBrowser1.NavigateToString(htmlCode);
You could have another webBrowser hidden under webBrowser1. Lets call it webBrowser2. Now when a user hits a link on webBrowser1, capture it a string lets say link. Now you can navigate to link using webBrowser2.Navigate(new Uri(link,UriKind.Absolute));. Do not forget to make webBrowser1 hidden and webBrowser2 visible.
If i understand you, you want to intercept the onClick event in your first WB control (call this WB1), and open that page up (when the hyperlink is clicked) in another WB control (call this WB2)?
There are several ways you can do this, is this link set to open up in a new window? If so, you can intercept the NewWindow2 event is WB1 and run the following code in the NewWindow2 event of WB1...
Set pDisp = WB2.object
(it may be ppDisp instead of pDisp, but it will show up when your event is auto generated, choose whichever object name shows up in your arguments list).
Otherwise, you can intercept this request during BeforeNavigate2 event of the WB1 event, check the URL property if it is the link you're interested in, and if so, cancel the current request and reissue a new one as below... (in the WB1 BN2 event)...
Cancel = True ' This cancels the request
WB2.Navigate2 URL, , "YourWB2sDocumentNameOrTargetFrameNameGoesHere"
Second line of code just reissues the request.
Of course, the YourWB2sDocumentNameOrTargetFrameNameGoesHere is the TargetFrameName (or the frame or document name of the top level document, or any iframe, in your WB2 control/window). This can usually be found in the BODY tags name= property, but you don't even need to do this if all you want is to load it as the top level document in WB2... if you just want to load it as the parent top level document in WB2, just do this...
Cancel = True
WB2.Navigate2 URL
By referencing WB2 it will just send the same URL request to WB2 window after cancelling WB1 request.
Let me know if you need more help and let me know how you get along.

Resources