Selenium set Element Discovery timeout wait time-python__python

Source: Internet
Author: User
Tags set time

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.