Selenium : After clicking a Click in home page , one more screen appears and it got altogether different new DOM loaded - selenium

Selenium : After clicking a Click in home page , one more screen appears and it got altogether different new DOM loaded and am currently unable to handle any elements using selenium and getting Element not found exception
Note : Tried Manually to load the same page and in browser console provided the same element and got nothing . but after long time it shows element. Is there a way to handle it?

You can handle your child window using below code. Basically we need to switch web driver control from your parent window to child window and once you finish process then again you have to switch control back to your parent window for further process. We can use window_handles to get handle of all opened windows by web driver and then we can switch from one window to another in a web application
Different Windows
Python :
driver.switch_to_window(driver.window_handles[-1])
title=driver.title
To handle synchronisation issue you can always use different types of waits available in the selenium e.g: implicit, explicit etc.

Related

Robotframework - Selenium - How to verify page loaded completely (successfully) without relying on a specific element in the page?

I was wondering if there is anything in Selenium that can verify if a page loaded completely without relying on a specific element in the page to appear (while using the "wait until page contains" or similar keywords).
The idea is reusability. If there is a need to add new websites to the robot automation later, I do not want to rely on a specific element that might exist in one page but not in another to verify if the page loaded fully.
Is there any keyword that addresses that in Robot Framework - Selenium Library?
Thanks!
Edit - I am aware that some AJAX requests are impossible or extremely difficult to conclude if they finished or not (or if they just keep going forever) so let's assume the website does not have any of that.
Once the page is finished loading, all requests are done.
driver.execute_script("return document.readyState === 'complete'")
use execute script document.readyState , if it returns complete it means the loading have finiished.
But if there is no ajax you don't have to do it selenium does it automatically so your question won't be valid:
https://www.selenium.dev/documentation/en/webdriver/page_loading_strategy/#:~:text=Defines%20the%20current%20session's%20page,loading%20takes%20lot%20of%20time.
normal This will make Selenium WebDriver to wait for the entire page
is loaded. When set to normal, Selenium WebDriver waits until the load
event fire is returned.
By default normal is set to browser if none is provided.
I couldn't find some built-in option but there is another way to achieve this. Check if your web app uses any third-party library which shows progress bar, if yes then probably there is function which returns the status of page loading including Ajax call. If not, then you can ask devs to add some progress bar, for instance Pace.JS
document.readyState does not wait for Ajax calls, personally I found it less helpful.

Problem of Jmeter/Webdriver with testing a webapp searching data form which has Knockout installed

I am facing problem of testing jmeter/Webdriver for a webapp which has Knockout framework installed. I fill all the form fields OK but when run click search button it displays the error that required fields need not to be empty. I checked all web element value are not empty. As my understand Knockout is not activated to bind Web elements with DataModel from Knockout. I used wait WDS.browser.manage().timeouts().implicitlyWait for webpage fully loaded/ajax calling or event being fired but without any success. I Do you have any experiencing and solution for testing this kinds of webapp?
thanks
It might be the case you need to trigger a certain JavaScript event in order to "tell" the web application that you finish the input, i.e. onkeyup or onblur which is not being automatically called by Selenium's sendKeys() function
You can use i.e. WDS.browser.executeScript() function to send the event(s) which indicate that you filled in the form(s). Check out The WebDriver Sampler: Your Top 10 Questions Answered article to learn how to call scripts, use Waits, etc.

Does Selenium/Protractor look for element in current loaded page?

Does Selenium/Protractor look for element in current loaded page, or look in the entire application when using the same Css Selector for same elements?
Eg:
Save Button on Customers Form class="save"
Save Button on Vendors Form class="save"
Protractor works by interacting with the browser (via selenium). Selenium uses browser drivers to interact with your page, and the browser only contains the code that it asked for (returned from the server, based on the type of request that was made).
So yes, it only looks for elements in the currently loaded page. It has no access to your entire application code.
Selenium looks for the element only on the loaded page. Not sure about Protractor though.

How to pass control to a new window(not popup) in selenium?

My site has a link which navigate to another site. I have to check whether the link taking the user to correct website. The following is the code i've written to pass control
selenium.click("link=target window");
selenium.selectWindow("Title of target window");
assertTrue((selenium.isTextPresent("content in target window")));
selenium.close();
selenium.selectWindow("null");
But if i run this i'm getting error like "Could not find window with title ... "
There is information about how the selectWindow() function locates the window here. In particular,
If you're having trouble figuring out what is the name of a window
that you want to manipulate, look at the selenium log messages which
identify the names of windows created via window.open (and therefore
intercepted by selenium). You will see messages like the following for
each window as it is opened:
debug: window.open call intercepted;
window ID (which you can use with selectWindow()) is "myNewWindow"

Difference between selenium.selectFrame() and selenium.selectWindow()

I've been struggling with the difference between the following commands, used while accessing widgets contained within iframes:
selenium.selectFrame("widget0");
selenium.selectWindow("name=widget0");
In the past (prior to IDE v1.0.12), I have been using these interchangeably, preferring the former over the latter in most cases. However, with 1.0.12, swapping them out after recording does not work. In what cases would each one be used?
Thanks.
selectFrame is the API of selenium to select a particular frame form HTML source.
Say, some HTML elements are present inside a iframe of HTML source, therefore u are
not able to take event on those elements until to use selectFrame API.
selectWindow will be used in those cases where after take some event a new browser popup
window open and u need to take action on the popup window instead of main browser page.
After doing ur operation u need to select back ur main browser window.