Wednesday, August 29, 2018

Selenium : How To Avoid Page Loading On Exam Execution

| Wednesday, August 29, 2018
If you lot site Is large together with thus amount page tin john accept to a greater extent than fourth dimension to acquire loaded completely. In such sites, Single activity (like click on link on abode page) tin john accept to a greater extent than fourth dimension equally page takes to a greater extent than fourth dimension to acquire fully loaded because WebDriver volition expect for page acquire loaded successfully. Can nosotros avoid or neglect this page loading to perform click activity fifty-fifty page loading Is In process? Yes nosotros tin john practise It In Firefox driver.

Earlier nosotros learnt many examples on how to practise Firefox custom profile for selenium spider web driver examine on run fourth dimension to Download Different FilesHandle SSL CertificateDisable JavaScript,etc. We volition purpose same concept hither to avoid page loading to click on button.

We tin john practise Firefox driver's custom profile together with laid upward preference webdriver.load.strategy = unstable for novel created profile volition practise our chore equally shown bellow.

//Create custom profile together with laid upward preference webdriver.load.strategy = unstable FirefoxProfile fp = novel FirefoxProfile(); fp.setPreference("webdriver.load.strategy", "unstable");    //Load firefox driver amongst custom profile. driver =new FirefoxDriver(fp);

I conduct maintain created amount sample instance to demonstrate you lot how click on push chemical component 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 cast AvoidPageLoad {  WebDriver driver;   @BeforeTest  populace void setup() throws Exception {   // Create custom profile together with laid upward preference webdriver.load.strategy = unstable   FirefoxProfile fp = novel FirefoxProfile();   fp.setPreference("webdriver.load.strategy", "unstable");    // Load firefox driver amongst custom profile.   driver = novel FirefoxDriver(fp);   driver.manage().window().maximize();   driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);   driver.get("aa/search?q=how-to-download-different-files-using");  }   @Test  populace void clickBeforeLoad() {   // This activity volition non expect for page to charge completely.   // Click activity volition last performed during page load.   driver.findElement(By.xpath("//button[@onclick='myFunctionf()']")).click();   System.out.println("Button got clicked");  } }

When you lot run inwards a higher house example, Webdriver volition click on "Show Me Prompt" push fifty-fifty page loading Is In procedure equally shown In bellow Image.

So It has't waited to page charge fully together with clicked on push during page loading Is In process. This agency nosotros tin john avoid page loading to perform actions In selenium WebDriver to salve examine execution time.

Related Posts