Stop browser load from selenium webdriver

后端 未结 3 1261
生来不讨喜
生来不讨喜 2020-12-28 22:09

My selenium webdriver goes to a page and waits for that page to finish loading. If 30 seconds pass it times-out and the script fails.

Is there anyway to have the

相关标签:
3条回答
  • 2020-12-28 22:54

    Try using this:

       driver.manage().timeouts().pageLoadTimeout();
    

    Documentation:
    Page Load Timeout

    Also, as a tip, you cannot access native controls of the browser using Selenium WebDriver. If you want to do that, use tools like Sikuli if you are using Linux or AutoIt for windows.

    0 讨论(0)
  • 2020-12-28 23:03

    You can stop page loading in Ruby using JavaScript function window.stop() and method Selenium::WebDriver::Driver#execute_script:

    driver.execute_script("window.stop()")
    
    0 讨论(0)
  • 2020-12-28 23:11

    This is the way I came across this issue. I will be using this way until chrome supports pageload.

    I installed an extension in chrome called Stop load and I set 5 secs stop load.

    Then I initiated my driver with the default setting -

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setCapability("chrome.switches", Arrays.asList("--user-data-dir="+System.getProperty("user.home")+"\\AppData\\Local\\Google\\Chrome\\User Data"));
    System.setProperty("webdriver.chrome.driver", "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe");
    driver = new ChromeDriver(capabilities); 
    

    if the page in chrome does not load in 5 secs, your extension will take care of it by killing it in 5 Seconds.

    In a way it works like a implicitwait if you set the proper stop load time in the extension

    0 讨论(0)
提交回复
热议问题