How can I place a LoadPage in Selenium globally

0

Good day, I'm automating a web application (With JAVA-Selenium), since I have to wait between pages, I'm using the Thread.sleep but it makes me a bad practice because I'm putting it between each line of code, I'd like to know if there is an extension or a line of code that allows to define globally in the project that each line of code is executed immediately the page has been fully loaded

I appreciate help

    
asked by BlackWidow 16.06.2017 в 19:04
source

1 answer

0

To avoid using the Thread.sleep in Selenium you have two types of waits, implicit and explicit .

The implied waits is the time that WebDriver waits to find an item that is not available and is defined when the WebDriver is created >.

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

Explicit waits is the amount of time you wait until a condition is met to search for an item.

WebElement myDynamicElement = (new WebDriverWait(driver, 10))

.until (ExpectedConditions.presenceOfElementLocated (By.id ("myDynamicElement")));

There are many types of conditions such as an element that is visible, clickable, its value is X, etc. etc.

Here you have a link with the Selenium documentation where they explain in more detail the waits and the types of waits:

link

And here the Selenium documentation with all types of conditions:

link

    
answered by 01.07.2017 в 11:26