How do you make Selenium 2.0 wait for the page to load?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Imran's answer rehashed for Java 7:
NodeJS Solution:
In Nodejs you can get it via promises...
If you write this code, you can be sure that the page is fully loaded when you get to the then...
If you write this code, you will navigate, and selenium will wait 3 seconds...
From Selenium documentation:
this.get( url ) → Thenable
Schedules a command to navigate to the given URL.
Returns a promise that will be resolved when the document has finished loading.
Selenium Documentation (Nodejs)
If you want to wait for a specific element to load, you can use the
isDisplayed()
method on aRenderedWebElement
:(Example from The 5 Minute Getting Started Guide)
I'm surprised that predicates weren't the first choice as you typically know what element(s) you will next interact with on the page you're waiting to load. My approach has always been to build out predicates/functions like
waitForElementByID(String id)
andwaitForElemetVisibleByClass(String className)
, etc. and then use and reuse these wherever I need them, be it for a page load or page content change I'm waiting on.For example,
In my test class:
In my test class parent:
Though this seems like a lot, it takes care of checking repeatedly for you and the interval for how often to check can be set along with the ultimate wait time before timing out. Also, you will reuse such methods.
In this example, the parent class defined and initiated the
WebDriver driver
and theWebDriverWait driverWait
.I hope this helps.
If someone uses selenide:
More Conditions can be found here: http://selenide.org/javadoc/3.0/com/codeborne/selenide/Condition.html
Use class WebDriverWait
Also see here
You can expect to show some element. something like in C#: