简体   繁体   中英

Selenium code to wait until CSS class is available and extract text in Python

I have looked at some questions on here that are somewhat related but none of them are concerned with finding a class and then extracting text that is part of that class.

My goal is to automate the process of entry into a website that finds emails, given name and domain names. So far I have the code to automate the entry of the name and domain, and then click on "search", but my issue is waiting for a result to load. I basically want my code wot wait until the CSS class "one" is present and then extract the text related to this class, eg for the following snippet:

<h3 class="one">Success</h3>

Extract the text "Success".

You need to explicitly wait for the element to become visible :

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
h3 = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "h3.one")))
print h3.text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM