Preface: wrote a script before, want in the IP site inquires over more than 1000 domain name the record information, but some domain name is not the record, therefore cannot find the element, although I already set the unusual judgment, but the default waiting 30 seconds time let me unbearable. Then after a variety of Baidu found a solution.
Digression: A colleague uses Nodejs to solve more than 1000 data in 2 minutes by means of an asynchronous contract.
Let's talk about the statements in Java Riga
In webdirver driver = new Firefoxdriver (); (may be other browser-driven, it doesn't matter.) ) after, plus.
driver.manage (). Timeouts (). implicitlywait (3, timeunit.seconds); The default is 30 seconds, you can change the dots.
And then in our Python environment:
#导入 webdriverwait Bag
From Selenium.webdriver.support.ui import webdriverwait
#导入 Time Package Import time
Sleep () Set fixed wait time
--such as: Time.sleep (5) #等待5秒
Implicitly_wait () waits for an element to be discovered, or a command completes, throws an exception when the setting time exceeds
--such as: driver.implicitly_wait (30)
DRIVER.FIND_ELEMENT_BY_ID ("id"). Click ()
Webdriverwait () at set time, the default is detected every once in a while
Detects if the current page element exists and throws an exception if the setting time is not detected
Webdriverwait (Driver, timeout, poll_frequency=0.5, Ignored_exceptions=none)
--driver:webdriver driver (Ie, Firefox, Chrome or remote)
--timeout: Maximum timeout time, default in seconds
--poll_frequency: Interval (step) time of hibernation time, defaults to 0.5 seconds
--ignored_exceptions: Exception information after timeout, throw nosuchelementexception exception by default
--such as 1:element = Webdriverwait (Driver). Until (lambda
X:X.FIND_ELEMENT_BY_ID ("id"))
Element.send_keys ("Selenium")
-such as 2:element = Webdriverwait (Driver). Until (lambda x:x.find_element_by_id ("id")
is_disappeared = webdriverwait (Driver, 1, (Elementnotvisibleexception)). Until_not (Lambda
x:x.find_element_by_id ("Someid"). Is_displayed ())
Webdriverwai () is typically used in conjunction with the unit () or Until_not () method:
--until (method, message= ') invokes the driver provided by the methods as a parameter until the return value is not False. --until_not (method, message= ') invokes the driver provided by the methods as a parameter until the return value is False.