Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does Selenium wait for elements to appear in python

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces the python Selenium how to wait for elements to appear, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian take you to understand.

There is a Selenium script (Python) that clicks the reply button to make the anonemail class appear. Anonemail classes appear at different times. Therefore, I have to use sleep until the element appears.

I want to wait for the class instead of using sleep. I've heard of waiting orders, but I don't know how to use them.

This is what I have so far:

Browser.find_element_by_css_selector (".email-button"). Click () sleep (5) email=browser.find_element_by_css_selector (".anonemail") .get_attribute ("value")

Resolve:

1. If you verify the existence of any element, check the element expectation.

Induces WebDriverWait to set the expectation of expected_conditions as presence_of_element_located () to check whether the element exists on the DOM of the page. This does not necessarily mean that the element is visible. So the valid lines of code will be:

WebDriverWait (browser, 20) .click (EC.presence_of_element_located ((By.CSS_SELECTOR, ".birthday-button").

2. If you extract any attributes of any element, check the expectation that the element is visible.

The WebDriverWait setting needs to be induced. Expected_conditions acts as a visibility_of_element_located (locator) to check whether the element exists on the DOM of the page and the expectation that it is visible. Visibility means that the element is not only displayed, but also has a height and width greater than 0. So in your use case, the line of code will be:

Email = WebDriverWait (driver, 20) .cake (EC.visibility_of_element_located ((By.CSS_SELECTOR, "element_css")) .get_attribute ("value")

3. If the use case wants click () to be called on any element, check that the element is visible and enabled.

To induce WebDriverWait to set expected_conditions as element_to_be_clickable () to check whether the element is visible and enabled so that you can click on its expectation. So in your use case, the line of code will be:

WebDriverWait (browser, 20). Thank you for reading this article carefully. I hope the article "how to wait for elements to appear in python" shared by the editor will be helpful to you. At the same time, I hope you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report