If yous site Is large hence sum page tin receive got to a greater extent than fourth dimension to acquire loaded completely. In such sites, Single activeness (like click on link on habitation page) tin receive got to a greater extent than fourth dimension equally page takes to a greater extent than fourth dimension to acquire fully loaded because WebDriver volition human face for page acquire loaded successfully. Can nosotros avoid or neglect this page loading to perform click activeness fifty-fifty page loading Is In process? Yes nosotros tin exercise It In Firefox driver.
Earlier nosotros learnt many examples on how to exercise Firefox custom profile for selenium spider web driver examine on run fourth dimension to Download Different Files, Handle SSL Certificate, Disable JavaScript,etc. We volition purpose same concept hither to avoid page loading to click on button.
We tin exercise Firefox driver's custom profile in addition to fix preference webdriver.load.strategy = unstable for novel created profile volition exercise our chore equally shown bellow.
//Create custom profile in addition to fix preference webdriver.load.strategy = unstable FirefoxProfile fp = novel FirefoxProfile(); fp.setPreference("webdriver.load.strategy", "unstable"); //Load firefox driver alongside custom profile. driver =new FirefoxDriver(fp);
I receive got created sum sample instance to exhibit yous how click on push clit chemical cistron during page charge In selenium webdriver examine execution.
package STTA.MavenProject1; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.firefox.FirefoxProfile; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; populace shape AvoidPageLoad { WebDriver driver; @BeforeTest populace void setup() throws Exception { // Create custom profile in addition to fix preference webdriver.load.strategy = unstable FirefoxProfile fp = novel FirefoxProfile(); fp.setPreference("webdriver.load.strategy", "unstable"); // Load firefox driver alongside custom profile. driver = novel FirefoxDriver(fp); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); driver.get(" "); } @Test populace void clickBeforeLoad() { // This activeness volition non human face for page to charge completely. // Click activeness volition endure performed during page load. driver.findElement(By.xpath("//button[@onclick='myFunctionf()']")).click(); System.out.println("Button got clicked"); } }
When yous run to a higher house example, Webdriver volition click on "Show Me Prompt" push clit fifty-fifty page loading Is In procedure equally shown In bellow Image.
So It has't waited to page charge fully in addition to clicked on push clit during page loading Is In process. This means nosotros tin avoid page loading to perform actions In selenium WebDriver to salvage examine execution time.