1 #-*-coding:utf-8-*-2 fromSeleniumImportWebdriver3 fromSelenium.webdriver.common.action_chainsImportActionchains4 fromSelenium.webdriver.support.uiImportwebdriverwait5 6 Import Time7 8Driver = Webdriver. Firefox (executable_path='/users/huiliang/downloads/geckodriver')9Driver.get ("http://www.baidu.com/")Ten OneWebdriverwait (Driver). Until (LambdaX:X.FIND_ELEMENT_BY_ID ('kw'). Send_keys ("Lambda") A " " - driver returns an instance of the browser - Ten Timeout Timeout the poll_frequency loop to query the gap time, the default is 0.5 seconds, can be omitted - lambda function in short, I need a function now, but I don't want to bother naming a function, which is an anonymous function . - The x inside the lambda, which is the input parameter, refers to the driver, and the return value after the colon - + adding too much sleep can affect the speed of script execution - so both the display and the implicit are good choices. + " " A at -Time.sleep (5) -Driver.quit ()
Selenium python explicit and implicit wait methods