ohbrobig
ohbrobig

Reputation: 966

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, e.g. for the following snippet:

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

Extract the text "Success".

Upvotes: 7

Views: 21298

Answers (1)

alecxe
alecxe

Reputation: 473903

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

Upvotes: 14

Related Questions