Development Environment:
win10-64 python2.7.16 chrome77
from the Selenium Import webdriver Driver = webdriver.Chrome (executable_path = ' chromedriver.exe ' ) driver.get ( ' HTTP: // All loaded super slow website ' ) the User = ' abc ' pwd = ' 123 driver.find_element_by_id ( ' In Email ' ) .send_keys (User) driver.find_element_by_id ( ' Pass ' ) .send_keys (pwd)
Look at this piece of code
When executed get, unless the site all loaded, otherwise you can only obediently like nothing capable, this is the whole process is blocked, get finish it could not perform the following operation
The wait may be 5 minutes or longer
In fact, five seconds when the interface has been opened, and then he was still loaded what js, img, waiting super-slow speed, but can operate manual pages
Is there any way to do online to find a pass, gives a lot of solutions
The first is that the goods (Here is my copy):
Import the webdriver Selenium from
Driver = webdriver.Chrome ()
driver.set_page_load_timeout (. 5)
driver.set_script_timeout (. 5) # are both set to be effective for
the try: d.get (S) the except: d.execute_script ( 'window.stop ()') # This sentence seems to be no soft with
You can continue to operate after the stop loading a page
driver.set_page_load_timeout (5) a set this thing, no problem, 5 seconds after the page is really stopped, but the driver also died, no matter what operation is timeout, and said try it, through the driver is dead, can only be re
I do not know selenium update or he did not test or chrome update, and now such a set is seeking death
Note: use set_page_load_timeout time, when the page does not load any things (often the html source code is not loaded), because of timeout to stop , driver will lead to failure,
the latter driver can not operate, so that the timeout should be set up at least a portion of contents of the page is loaded, sets the timeout should not be too short, as shown in the failure to stop loading page driver this state.
Yes, some people have said, can not be set too short, it will fail, but I can say that you set five minutes still fail, as long as the time-out time, driver is finished, a direct rollover
followed by another method
# coding = utf-8 from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait import time driver = webdriver.Chrome() class button(): def __call__(self, driver): if driver.find_element_by_id('js_love_url'): return True else: return False driver.implicitly_wait(60) time_start = time.time() driver.get('https://www.163.com/') # driver.find_element_by_id('js_love_url').click() WebDriverWait(driver,2,0.5).until(button()) time_end = time.time() print('access time is : ', time_end - time_start) time.sleep(2) driver.quit()
WebDriverWait operation carried out with, but I tested down, driver.get () not been executed, the following code would not execute, it does not work
Find a variety of methods, various operations have failed, today finally found the right way
Principle is very simple: driver.get () This operation is changed to a non-blocking on the line, so open the page on completion of the operation, so he does not need to be loaded
Now I can wait for the direct elements needed appear to operate
Configuration is very simple
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities #get直接返回,不再等待界面加载完成 desired_capabilities = DesiredCapabilities.CHROME desired_capabilities["pageLoadStrategy"] = "none"
driver = webdriver.Chrome(executable_path='chromedriver.exe')
A configuration parameter, the page is loading strategy, the default is to wait, so he is finished loading, directly to none, just do not wait, this is get directly after the operation is ended
The following does not affect the operation, so you can play the happy