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".
Fluent Wait in Selenium marks the maximum amount of time for Selenium WebDriver to wait for a certain condition (web element) becomes visible. It also defines how frequently WebDriver will check if the condition appears before throwing the “ElementNotVisibleException”.
There are three ways to implement Selenium wait for page to load: Using Implicit Wait. Using Explicit Wait. Using Fluent Wait.
Implicit Waits. An implicit wait tells WebDriver to poll the DOM for a certain amount of time when trying to find any element (or elements) not immediately available. The default setting is 0 (zero). Once set, the implicit wait is set for the life of the WebDriver object.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With