IEDriver Wait Loading page - selenium

I am using selenium IEDriverServer along with python.
Is it possible to make sure that IEDriverServer waits for a page to load , until some time and if the operation is not complete in time then it stops loading the page and we can proceed to next step.
Actually i am using a test page which contains takes too much time to load. All i am trying to do is to let it wait for the page to load until 10 sec and if it is unable to load in that time then it stops loading that page and moves over to the next step.
Can anyone suggest how this can be achieved in selenium

Webdriver has both implicit waits as well as explicit waits.
Implicit means it implicitly waits for the specified time on all actions.
driver.implicitly_wait(10)
Explicit means you can specify to wait for an expected condition to be met, which can be set for a page or some specific element
element = wait.until(EC.element_to_be_clickable((By.ID,'someid')))
Documentation here

Related

Selenium command taking more time than specified in wait

I have a selenium test to navigate to a login page. Enter user name and password and click the login button. Once logged in, check whether an element is present in the home page.
I am keeping track of the time each command takes
WebDriver driver = driver.manage().timeouts().pageLoadTimeout(30L, TimeUnit.SECONDS);
driver.get("<url>");
WebDriverWait webDriverWait = new WebDriverWait(driver, 20);
Even though my wait is for 20 seconds, When I check the total time for this command to execute it can take up to 30 (this happens on failed logins). I am trying to figure out why selenium is taking 30 seconds instead of 20 in case of failures? I read through the documentation etc but no where did I see that pageLoadTimeout impacts loading when a button is clicked.
It seems like the driver.get("<url>"); command takes some time.
Means the page needs some time to load. You could load the page threaded tho.

Selenium - when exactly the webdriver instance gets updated?

I'm using selenium to automate a task on a very dynamic website with pyhton.
For this reason certain HTML elements of the current loaded page may or may not be present at the moment of the request from my code.
How exactly the webdriver instance gets updated and receives the new data from the web page?
Is it constantly connected and receive the change in the HTML code instantly?
Or it first download a first verion of the page when driver.get() is called, and then updates it whenever a function such as .find_element_by_class_name() is called?
Q. Is it constantly connected and receives the change in the HTML code instantly?
Ans. Well, for each Selenium command, there will be an HTTP request that will send to the browser driver and then to the server and the command will get, A HTTP response will be returned and the command/commands will get executed based on the response.
Now let's say in a situation you do,
driver.get()
Basically, this is a selenium command.
It would fire an HTTP request stating to launch the URL provided. Based on the response (200-Ok or anything else), you would either see the WebPage getting loaded or an error message.
Same way in Sequence all the Selenium commands will get executed.
It's obvious that we need locators to locate web elements in the UI.
Once we have them, we can tightly couple them with
driver.find_element_by_***
methods.
Things to be noted down here
You need to learn/understand :
Implicit Waits.
Explicit Waits.
Fluent Waits.
Implicit Waits :
By implicitly waiting, WebDriver polls the DOM for a certain duration when trying to find any element. This can be useful when certain elements on the webpage are not available immediately and need some time to load.
Basically what it means is, whenever you use drive.find_element it gonna look for implicit waits if you have defined one.
If you've not defined one implicit wait, then the default value is 0.
Explicit wait
They allow your code to halt program execution, or freeze the thread, until the condition you pass it resolves. The condition is called with a certain frequency until the timeout of the wait is elapsed. This means that for as long as the condition returns a falsy value, it will keep trying and waiting.
FluentWait
FluentWait instance defines the maximum amount of time to wait for a condition, as well as the frequency with which to check the condition.
Reference Link
Updated :
PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.
Steps to check:
Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the xpath and see, if your desired element is getting highlighted with 1/1 matching node.
Locators (by priority from top):
ID
name
classname
linkText
partialLinkText
tagName
css selector
xpath
Web page is loaded by driver.get().
But the driver doesn't "know" what elements are existing there. It just opens, loads the web page.
To access any element, to check element presence etc. you will need to do that particularly per each specific element / elements using commands like .find_element_by_class_name() with a specific element locator.

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.

Selenium script fails on every step, exception "noSuchElementFound"

The Reason for this issues is the website page not loaded fully. Elements are visible and even clickable but loading message other fly messages doesn't allow to any action on the webpage. I already implemented all type of wait, still few steps keeps on failing. Is there any wait which check page is loaded or not? Using serenity framework.

PHPUnit and WebDriver(Selenium2) - How to operate an element before the page's fully loaded?

By default , Webdriver always wait for a page's full loading, then find the element on this page and operate it.
e.g. open the google.com website, wait for its full loading, then find the search button ,and click it.
Sometimes, the page connects to some external link ,such as GA (statistics service), which usually takes too much time. And the button that I want to click has been loaded before the page's completely loaded.
How can I let Webdriver click a button when the button has been loaded ,when other parts of the page are still in loading progress?
You could always put a wait command in there.
sleep(5);
This will make it ' sleep for 5 seconds '
Though, it's easier to use ' waitForElementPresent();
$this->waitForElementPresent("YOURELEMENT","50000");
this will make your script wait for 50 seconds or until the element is loaded
YOURELEMENT = the locator
50000 = The timeout