7

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".

1 Answer 1

14

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
Sign up to request clarification or add additional context in comments.

10 Comments

I am getting this error: File "/Users/sinaastani/AskNorbert/finder.py", line 18, in <module> h3 = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "h3.one"))) File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/selenium-2.45.0-py3.4.egg/selenium/webdriver/support/wait.py", line 75, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
@ohbrobig then, it appears that this element is not getting visible.
@ohbrobig any iframes on the page? Is the element really represented as <h3 class="one">Success</h3>? Thanks.
there are iframes on the page, but the element is really represented that way
@ohbrobig iframes are your current problem. You need to switch to an iframe and then wait for an element: driver.switch_to.frame('frame_id_or_name').
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.