java - How can I wait a page to load with selenium htmlunitDriver? -


i working on bot page similar ad.fly. after opening link, want wait 5 seconds page load before button click appears.

click link see mean: http://bc.vc/xhdgkn

i want execute htmlunitdriver. tried implicit wait , explicit wait, did not work. told me use fluentwait, don't know how implement it.

here actual code, can me understand how implement fluentwait?

public class bot {  public static webdriver driver; public static void main(string[] args) {      driver = htmlunitdriver();      driver.manage().timeouts().implicitlywait(10, timeunit.seconds);      driver.get("http://bc.vc/xhdgkn");      // here have use fluent wait, may explain me?      driver.findelement(by.id("skip_btn")).click(); // element have click when page load 5 seconds "skip ads button" } 

}

i method apply... grateful if :)

actually, fluentwait more suitable situation wait can range widely, let anytime between 1 10 seconds. example:

wait<webdriver> wait = new fluentwait<webdriver>(driver)         .withtimeout(10, timeunit.seconds)         .pollingevery(1, timeunit.seconds)         .ignoring(nosuchelementexception.class);  webelement el = wait.until(new function<webdriver, webelement>() {     public webelement apply(webdriver driver) {         return driver.findelement(by.id("skip_btn"));     } });  el.click(); 

just sure, these import statements need:

import com.google.common.base.function; import org.openqa.selenium.by; import org.openqa.selenium.nosuchelementexception; import org.openqa.selenium.webdriver; import org.openqa.selenium.webelement; import org.openqa.selenium.support.ui.fluentwait; import org.openqa.selenium.support.ui.wait; import java.util.concurrent.timeunit; 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -