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_har_is_updating():
try:
mob = mobidriver.Firefox(BROWSER_MOB_PATH, headless=True)
test_url = 'http://jkorpela.fi/forms/testing.html'
mob.get(test_url)
WebDriverWait(mob, 2).until(EC.title_is('Testing HTML forms'))
first_har = mob.har
mob.find_elements_by_tag_name('input')[2].click()
WebDriverWait(mob, 2).until(EC.title_is('Echoing submitted form data'))
new_har = mob.har
assert first_har != new_har
finally:
mob.quit()
def wait(self, el_type=By.TAG_NAME, el_value="body", timeout=30):
print(" - waiting for page by {0}: {1} ...".format(el_type, el_value))
element = WebDriverWait(self.driver, timeout).until(
exp_cond.presence_of_element_located((el_type, el_value)))
def wait_for_element_by_css_selector(self, selector, timeout=TIMEOUT):
return WebDriverWait(self.driver, timeout).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector)),
'Could not find element with selector "{}"'.format(selector)
)
def waitLogRuleModal(browser):
WebDriverWait(browser, 10).until(Condition.visibility_of_element_located((By.ID, 'show-log-automation-rule-modal')))
modals.waitForOpened(browser.find_element_by_id('show-log-automation-rule-modal'))
return LogRuleModal(browser.find_element_by_id('show-log-automation-rule-modal'))
self.driver.implicitly_wait(3.5)
with apiritif.transaction_logged(self.template('/')):
self.driver.get(self.template('http://blazedemo.com/'))
WebDriverWait(self.driver, 3.5).until(econd.presence_of_element_located((By.XPATH, self.template("//input[@type='submit']"))), 'Element "//input[@type=\'submit\']" failed to appear within 3.5s')
self.assertEqual(self.driver.title, self.template('BlazeDemo'))
ActionChains(self.driver).move_to_element(self.driver.find_element(By.XPATH, self.template('/html/body/div[2]/div/p[2]/a'))).perform()
ActionChains(self.driver).double_click(self.driver.find_element(By.XPATH, self.template('/html/body/div[3]/h2'))).perform()
ActionChains(self.driver).click_and_hold(self.driver.find_element(By.XPATH, self.template('/html/body/div[3]/form/select[1]'))).perform()
ActionChains(self.driver).release(self.driver.find_element(By.XPATH, self.template('/html/body/div[3]/form/select[1]/option[6]'))).perform()
Select(self.driver.find_element(By.NAME, self.template('toPort'))).select_by_visible_text(self.template('London'))
self.driver.find_element(By.CSS_SELECTOR, self.template('body input.btn.btn-primary')).send_keys(Keys.ENTER)
self.assertEqual(self.template(self.driver.find_element(By.ID, self.template('address')).get_attribute('value')).strip(), self.template('123 Beautiful st.').strip())
self.assertEqual(self.template(self.driver.find_element(By.XPATH, self.template('/html/body/div[2]/form/div[1]/label')).get_attribute('innerText')).strip(), self.template('${name}').strip())
WebDriverWait(self.driver, 3.5).until(econd.visibility_of_element_located((By.NAME, self.template('toPort'))), "Element 'toPort' failed to appear within 3.5s")
self.driver.find_element(By.NAME, self.template('toPort')).send_keys(self.template('B'))
self.driver.find_element(By.NAME, self.template('toPort')).clear()
self.driver.find_element(By.NAME, self.template('toPort')).send_keys(self.template('B'))
self.driver.find_element(By.NAME, self.template('toPort')).send_keys(Keys.ENTER)
self.driver.find_element(By.NAME, self.template('toPort')).clear()
self.driver.find_element(By.NAME, self.template('toPort')).send_keys(Keys.ENTER)
self.driver.find_element(By.XPATH, self.template('//div[3]/form/select[1]//option[3]')).click()
self.driver.find_element(By.XPATH, self.template('//div[3]/form/select[2]//option[6]')).click()
self.wnd_mng.switch(self.template('0'))
self.driver.execute_script(self.template("window.open('some.url');"))
self.wnd_mng.switch(self.template('win_ser_local'))
self.wnd_mng.switch(self.template('win_ser_1'))
self.wnd_mng.switch(self.template('that_window'))
self.wnd_mng.close(self.template('1'))
self.wnd_mng.close(self.template('win_ser_local'))
self.wnd_mng.close(self.template('win_ser_1'))
# 根据页面进入主页面,并等待搜索框id出现
print 'url: ', url
self.driver.get(url)
wait = WebDriverWait(self.driver, 20)
element = wait.until(EC.presence_of_element_located((By.ID, input_id)))
time.sleep(random.uniform(2.0, 3.0))
# 清空搜索框,搜索企业,点击搜索
element.clear()
element.send_keys(search_text)
element = self.driver.find_element_by_id(search_element_id)
element.click()
wait = WebDriverWait(self.driver, 30)
element = wait.until(
EC.presence_of_element_located((By.CLASS_NAME,
gt_element_class_name)))
time.sleep(random.uniform(2.0, 3.0))
print 'element: ', element.text
def wait_and_accept_alert(self):
"""Wait and accept alert present on the page."""
try:
Wait(self.driver, TIME_OUT).until(ec.alert_is_present())
self.driver.switch_to.alert.accept()
logger.info("alert accepted")
except selenium_exceptions.TimeoutException:
logger.error(
"Could Not Find Alert Within The Permissible Time Limit")
node1.click()
assert nLinks + 1 == driver.execute_script("return model.links.length"), "Reflexive link not created"
node2id = driver.execute_script("return model.nodes[model.nodes.length - 2].id")
node2 = driver.find_element_by_id(str(node2id))
webdriver.ActionChains(driver).drag_and_drop(node1, node2).perform()
time.sleep(1)
newID = "link" + str(driver.execute_script("return model.lastLinkID"))
# Wait for the new link to be created:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, newID)))
node1.click()
assert nLinks + 2 == driver.execute_script("return model.links.length"), "Link not created"
webdriver.ActionChains(driver).drag_and_drop(node2, node1).perform()
time.sleep(1)
newID = "link" + str(driver.execute_script("return model.lastLinkID"))
# Wait for the new link to be created:
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, newID)))
assert nLinks + 3 == driver.execute_script("return model.links.length"), "Link not created"
webdriver.ActionChains(driver).drag_and_drop(node2, node1).perform()
assert nLinks + 3 == driver.execute_script("return model.links.length"), "Link should not have been created"
# Test 'texttool'
# First - test on nodes
texttool = driver.find_element_by_css_selector("#texttool")
assert "selected" not in texttool.get_attribute("class"), "Text tool should be selected"
texttool.click()
assert "selected" in texttool.get_attribute("class"), "Text tool should be selected"
assert "selected" not in linetool.get_attribute("class"), "Line tool should have been deselected"
node1.click()
form = driver.find_element_by_css_selector(".renameinput")
form.send_keys("тест") # This will probably take additional work to run in python 2.x but works in python 3.4
form.send_keys(Keys.RETURN)
assert "тест" == driver.execute_script("return query.getNodeData(" + str(node1id) + ").name"), "Rename did not modify model correctly"
def waitForItem(driver, css, timeout=10):
WebDriverWait(driver, timeout).until(expected_conditions.visibility_of_element_located((By.CSS_SELECTOR, css)))
def switch_frames(driver, frame_name):
"""Navigate nested iFrames to select the application modal dialog.
Positional arguments:
driver -- the Selenium webdriver instance
frame_name -- the CSS selector of the frame to switch to
"""
wait = WebDriverWait(driver, 15)
frame = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, frame_name)))
driver.switch_to.frame(frame)
wait.until(EC.frame_to_be_available_and_switch_to_it(0))