from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
browser = webdriver.Firefox()
browser.get("url")
delay = 3 # seconds
try:
myElem = WebDriverWait(browser, delay).until(EC.presence_of_element_located((By.ID, 'IdOfMyElement')))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
from selenium import webdriver
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)
try:
next_page_elem = self.browser.find_element_by_xpath("//a[text()='%d']" % pageno)
except noSuchElementException:
break
print('page ', pageno)
next_page_elem.click()
# wait for the page to load
wait.until(
EC.presence_of_element_located((By.XPATH, "//a[@class = 'on' and . = '%d']" % pageno))
)
def wait_for_visibility(self, selector, timeout_seconds=10):
retries = timeout_seconds
while retries:
try:
element = self.get_via_css(selector)
if element.is_displayed():
return element
except (exceptions.NoSuchElementException,
exceptions.StaleElementReferenceException):
if retries <= 0:
raise
else:
pass
retries = retries - 1
time.sleep(pause_interval)
raise exceptions.ElementNotVisibleException(
"Element %s not visible despite waiting for %s seconds" % (
selector, timeout_seconds)
)