Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_login(self):
driver = self.driver
driver.get(self.base_url + "/")
# Assert logged in with the right username
with Annotator(driver):
self.register()
self.logout()
self.login()
picker = (By.CLASS_NAME, 'user-picker')
ec = expected_conditions.visibility_of_element_located(picker)
WebDriverWait(self.driver, 10).until(ec)
picker = driver.find_element_by_class_name('user-picker')
dropdown = picker.find_element_by_class_name('dropdown-toggle')
# Some bugs were fixed in selenium 2.35 + FF23 combo
# Unfortunately, that means we need test both options
try:
assert dropdown.text == 'test'
except AssertionError:
assert dropdown.text == 'test/localhost'
self.driver.find_element_by_id(
'services__action_deploy_env').click()
self.check_element_on_page(by.By.XPATH, c.Status.format(
'Deploying'))
common.wait(
lambda: len(self.driver.find_elements_by_xpath(
c.Status.format('Ready'))) == 2, timeout_seconds=900)
for _ in range(2):
self.driver.find_element_by_xpath(mc.ButtonDeleteComp).click()
self.driver.find_element_by_xpath(mc.ButtonConfDeleteComp). \
click()
# Wait for disappearing modal window
locator = (by.By.XPATH, mc.ModalWindow)
ui.WebDriverWait(self.driver, 20).until_not(
EC.visibility_of_element_located(locator))
deleted_package_names.append(pkg_name)
for p_name in deleted_package_names:
self.check_element_not_on_page(by.By.LINK_TEXT, p_name)
def explicit_wait(self):
"""Wait for common elements to be visible."""
WebDriverWait(self.driver, 5).until(
expected_conditions.visibility_of_element_located(
(By.TAG_NAME, 'facets-overview')))
WebDriverWait(self.driver, 5).until(
expected_conditions.visibility_of_element_located(
(By.TAG_NAME, 'facets-dive')))
def wait_for_visible_by_id(self, element_id, timeout_in_seconds=None):
"""
Waits for the element to become visible. First, checks if element is present. Does not raise Error on exception!
:param timeout_in_seconds:
:param element_id:
"""
if timeout_in_seconds is None:
timeout_in_seconds = self.timeout_to_determine_visibility_in_seconds
print "Executing wait_for_visible_by_id('{0}'), timeout_in_seconds is set to {1}".format(
element_id, timeout_in_seconds)
try:
WebDriverWait(self.driver, timeout_in_seconds).until(EC.visibility_of_element_located((By.ID, element_id)))
print "Element by id = '{0}' was located in DOM and is visible.".format(element_id)
except TimeoutException:
print "ERROR: Timed out: element by id = '{0}' not visible.".format(element_id)
print "Checking whether element by id = '{0}' present in the DOM.".format(element_id)
try:
self.driver.find_element_by_id(element_id)
print "Element by id = '{0}' is present in the DOM but not visible.".format(element_id)
except NoSuchElementException:
print "ERROR: Element by id = '{0}' not found in the DOM.".format(element_id)
return False
def scrapeTeamOVA(fromYear, toYear, csvPath):
if not os.path.exists(csvPath):
os.makedirs(csvPath)
# Start scraping.
browser = webdriver.Chrome()
browser.get("https://sofifa.com/teams/hot")
try:
WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((By.XPATH, "//a[@class='choose-version']")))
except TimeoutException:
print("Timed out waiting for page to load")
browser.quit()
# Clicks
for year in range(fromYear, toYear + 1):
filePath = "{}/{}-{}.csv".format(csvPath, year, year + 1)
# We don't need to pull the same data again
if year != getCurrentSeason() and os.path.exists(filePath):
continue
fifaVersion = str(format((year % 2000 + 1), '02d'))
ShowListButton = browser.find_element_by_xpath("//a[@class='choose-version']")
ShowListButton.click()
if hasattr(element, 'click'):
next_url = element.get_attribute('href')
try:
element.click()
except WebDriverException:
# See http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error
# first move mouse to the next element, some times the element is not visibility
selector = self.next_page_selectors[self.search_engine_name]
if selector:
try:
next_element = WebDriverWait(self.webdriver, 5).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector)))
webdriver.ActionChains(self.webdriver).move_to_element(next_element).perform()
# wait until the next page link emerges
WebDriverWait(self.webdriver, 8).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, selector)))
element = self.webdriver.find_element_by_css_selector(selector)
next_url = element.get_attribute('href')
element.click()
except WebDriverException:
pass
# wait until the next page was loaded
if not next_url:
return False
else:
return next_url
def the_item_notes_are_group1(step, group1):
selector = ("//*[@id='asset-view-details']"
"//div[@class='global-annotation-notes']"
"[contains(text(),'{}')]").format(group1)
wait = ui.WebDriverWait(world.browser, 5)
wait.until(visibility_of_element_located((By.XPATH, selector)))
def i_set_selection_assignment_visibility_to_value(step, value):
q = "//input[@value='{}']".format(value)
wait = ui.WebDriverWait(world.browser, 5)
elt = wait.until(visibility_of_element_located((By.XPATH, q)))
elt.click()
except Exception: # if anything goes wrong for any reason, give up on MFA
mfa_method = None
warnings.warn("Giving up on handling MFA. Please complete "
"the MFA process manually in the browser.")
except NoSuchElementException:
pass
finally:
driver.implicitly_wait(20) # seconds
# Wait until the overview page has actually loaded, and if wait_for_sync==True, sync has completed.
if wait_for_sync:
try:
# Status message might not be present straight away. Seems to be due
# to dynamic content (client side rendering).
status_message = WebDriverWait(driver, 30).until(
expected_conditions.visibility_of_element_located(
(By.CSS_SELECTOR, ".SummaryView .message")))
WebDriverWait(driver, wait_for_sync_timeout).until(
lambda x: "Account refresh complete" in status_message.get_attribute('innerHTML')
)
except (TimeoutException, StaleElementReferenceException):
warnings.warn("Mint sync apparently incomplete after timeout. "
"Data retrieved may not be current.")
else:
driver.find_element_by_id("transaction")
return driver