本文整理汇总了Python中selenium.webdriver.Firefox.implicitly_wait方法的典型用法代码示例。如果您正苦于以下问题:Python Firefox.implicitly_wait方法的具体用法?Python Firefox.implicitly_wait怎么用?Python Firefox.implicitly_wait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.Firefox
的用法示例。
在下文中一共展示了Firefox.implicitly_wait方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FunctionalTests
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class FunctionalTests(LiveServerTestCase):
"""Base para os testes funcionais."""
def setUp(self):
"""Inicializa serviços necessários para execução dos testes funcionais."""
self.driver = Firefox()
self.driver.maximize_window()
self.driver.implicitly_wait(5)
def tearDown(self):
"""Finaliza serviços."""
self.driver.close()
def get_live_url(self, url_name):
"""Obtém url_name em relação ao servidor de testes."""
return '{}{}'.format(self.live_server_url, reverse(url_name))
示例2: browser
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
def browser(request):
"""
initialize the selenium test case
"""
profile = FirefoxProfile()
profile.set_preference("browser.download.folderList", 2)
profile.set_preference("browser.download.manager.showWhenStarting", False)
profile.set_preference("browser.download.dir", DOWNLOAD_DIR)
profile.set_preference("browser.helperApps.neverAsk.saveToDisk", "text/csv")
b = Firefox(firefox_profile=profile)
b.implicitly_wait(10)
b.maximize_window()
request.addfinalizer(lambda *args: b.quit())
yield b
time.sleep(10)
示例3: TestCustomDriver
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class TestCustomDriver(object):
def setUp(self):
self.driver = Firefox()
self.driver.implicitly_wait(1)
self.page = SimplePage(self.driver)
self.page.open()
def test_finds(self):
start = time()
eq_(len(self.page.empty_element_list), 0, 'List is not empty')
ok_(time() - start < 1, 'Implicitly wait works in Finds')
def test_nested_finds_in_container(self):
start = time()
eq_(len(self.page.physical_container.empty_element_list), 0, 'List is not empty')
ok_(time() - start < 1, 'Implicitly wait works in Finds')
def test_nested_finds_in_logical_container(self):
start = time()
eq_(len(self.page.logical_container.empty_element_list), 0, 'List is not empty')
ok_(time() - start < 1, 'Implicitly wait works in Finds')
def tearDown(self):
self.driver.quit()
示例4: WeixinSelenium
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class WeixinSelenium(Base):
def __init__(self):
self.start_page = START_PAGE
self.end_page = END_PAGE
self.weixin_url = REFER_FIRST
self.driver = Firefox()
self.client = MongoClient(HOST, PORT)
self.collection = self.client[DB][COLLECTION]
self.all_uids = self.uids
def open_weixin_browser(self, word):
try:
self.driver.get(self.weixin_url)
self.driver.set_page_load_timeout(3)
self.driver.find_element_by_id('upquery').send_keys(word)
self.driver.find_element_by_class_name('swz').click()
self.driver.implicitly_wait(3)
urls_uids = self.extract_urls_uids(word=word)
Article(urls_uids=urls_uids, word=word).extract()
except Exception as e:
storage_word.append([word, 0])
self.logger.info('Open weixin error: type <{}>, mag <{}>'.format(e.__class__, e))
self.close_browser()
return True
return False
def get_total_pages_to_word(self):
pages = []
page_id_css = 'pagebar_container'
try:
e = self.driver.find_element_by_id(page_id_css)
for _p in e.text.split():
_p = _p.strip()
if not _p.isdigit():
return pages[-1]
else:
pages.append(int(_p))
return 1
except (NoSuchElementException, NoSuchWindowException, TypeError, IndexError):
pass
def get_query_words(self):
query_words = []
for docs in self.collection.find({}, {'rel': 1, 'conp': 1}).sort([('_id', 1)]):
w = docs['conp']
if w not in query_words:
query_words.append(w)
for item in docs['rel']:
if item not in query_words:
query_words.append(item)
self.client.close()
return query_words
@property
def uids(self):
return {docs['uid'] for docs in in_collection.find({}, {'uid': 1}) if 'uid' in docs}
def extract_urls_uids(self, word):
urls_uids = []
timestamp = [_t.get_attribute('t') for _t in self.driver.find_elements_by_css_selector('div.s-p')]
urls_tits = [(t.get_attribute('href'), self.trim(t.text))
for t in self.driver.find_elements_by_css_selector('h4 a')]
if len(urls_tits) != len(timestamp):
return urls_uids
for index, url_tit in enumerate(urls_tits):
try:
uid = self.md5(timestamp[index] + url_tit[1] + word)
if uid not in self.all_uids:
self.all_uids.add(uid)
urls_uids.append({'url': url_tit[0], 'uid': uid})
except (TypeError, IndexError):
pass
return urls_uids
@staticmethod
def query_index(words, cut_word):
try:
index = words.index(cut_word)
return index
except ValueError:
pass
return 0
@property
def is_forbidden(self):
css_id = 'seccodeForm'
#.........这里部分代码省略.........
示例5: init_webdriver
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
def init_webdriver(self):
self.log.info("Inital Firefox as the testing webdriver!")
driver = Firefox()
driver.implicitly_wait(20)
driver.get(self.testurl)
return driver
示例6: scrape_section
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
def scrape_section(browser, section_name, total_page, page_link_id_prefix, table_id):
print "scrape {0} section...".format(section_name)
records = []
for i in range(1, total_page + 1):
print "click page " + str(i) + "..."
link = browser.find_element_by_id(page_link_id_prefix + str(i))
link.click()
time.sleep(5)
table = scrape_table(browser, table_id)
for row in table:
print row
records.append(row)
return records
def scrape_pru(browser, num, parliament_total_page, state_total_page):
# records = scrape_section(browser, "parliament", parliament_total_page, "ContentPlaceHolder1_PlnkPage", "ContentPlaceHolder1_gridParliamentResul")
# with open("pru{0}_parliament.json".format(num), 'w') as f:
# json.dump(records, f)
records = scrape_section(browser, "state", state_total_page, "ContentPlaceHolder1_NlnkPage", "ContentPlaceHolder1_grdAssemblyResult")
with open("pru{0}_state.json".format(num), 'w') as f:
json.dump(records, f)
browser = Firefox()
print "open website..."
browser.get("http://www.pru13.com")
browser.implicitly_wait(30)
scrape_pru(browser, 13, 12, 33)
browser.find_element_by_id("tab_menu2").click()
scrape_pru(browser, 12, 23, 51)
示例7: Hertz
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class Hertz():
def __init__( self ):
self.driver = Firefox()
#self.driver.get( 'https://www.hertzequip.com/herc/rental-equipment/aerial-equipment+manlifts+articulating-boom-lift' )
self.driver.implicitly_wait( 15 )
def perform_search( self, zip_code ):
self.driver.get( 'https://www.hertzequip.com/herc/rental-equipment/aerial-equipment+manlifts+articulating-boom-lift' )
# wait for javascript to load the page before we begin
self.driver.find_element_by_xpath( '//span[text()="View Rates"]' )
# selenium commands can be very unreliable
# since Jquery is already loaded, I'll use that
self.driver.execute_script( """
$('span:contains("View Rates")')[0].click()
$('input[id="postalCode"]').val('""" + zip_code + """')
$('a[class="button_four button_four_skin"]')[0].click()
""" )
# wait a few seconds for page element to disappear
sleep( 3 )
# wait until javascript has loaded the page again
self.driver.find_element_by_xpath( '//span[text()="View Rates"]' )
def get_rates( self ):
rates_info_json = self.driver.execute_script( """
var xmlhttp = new XMLHttpRequest()
var url = "https://www.hertzequip.com/herc/rest/rentals/getBuilderEquipmentDetailsItemInfo?catalogType=" + String( catalogType ) + "&categoryId=" + categoryId + "&subcategory1Id=" + subcategory1Id + "&subcategory2Id=" + subcategory2Id + "&_=" + String( new Date().getTime() )
xmlhttp.open( "GET", url, false )
xmlhttp.send()
return xmlhttp.responseText
""" )
return rates_info_json
def get_store_info( self ):
store_info_json = self.driver.execute_script( """
var xmlhttp = new XMLHttpRequest()
var url = "https://www.hertzequip.com/herc/rest/rentals/getBuilderJobLocationsItemInfo?_=" + String( new Date().getTime() )
xmlhttp.open( "GET", url, false )
xmlhttp.send()
return xmlhttp.responseText
""" )
return store_info_json
def perform_search_get_data( self, zip_code ):
self.perform_search( zip_code )
location_data = json.loads( self.get_store_info() )
equipment_rates_data = json.loads( self.get_rates() )
specific_data = OrderedDict()
specific_data['branch_zip_code'] = location_data['data']['jobLocation']['branchLocation']['zip']
specific_data['branch_id'] = location_data['data']['jobLocation']['branchLocation']['branch']
specific_data['equipment_list'] = []
for equipment in equipment_rates_data['data']['equipmentInfo']['m_list']:
equipment_data = OrderedDict()
equipment_data['specs'] = [ equipment['spec1'], equipment['spec2'] ]
equipment_data['makes & models'] = equipment['makesModels']['m_list']
equipment_data['rates'] = equipment['ratesInfo']
specific_data['equipment_list'].append( equipment_data )
return {
'location_data' : location_data,
'equipment_rates_data' : equipment_rates_data,
'specific_data' : specific_data
}
示例8: NewTrainingData
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class NewTrainingData(LiveServerTestCase) :
def setUp(self) :
# TODO setup lists with test data here, and make the 2 methods user_sees and check_entered accept these lists
self.browser = Firefox()
self.browser.implicitly_wait(3)
def tearDown(self) :
self.browser.quit()
def user_sees_inputfields_and_enters_data(self, distance, executed_time, in_zone, average_heart_rate) :
# user sees 4 edit boxes to enter distance, executed time, in zone and average HR
distance_editbox = self.browser.find_element_by_name('distance')
self.assertIsNotNone(distance_editbox)
executed_time_editbox = self.browser.find_element_by_name('executed_time')
self.assertIsNotNone(executed_time_editbox)
in_zone_editbox = self.browser.find_element_by_name('in_zone')
self.assertIsNotNone(in_zone_editbox)
average_heart_rate_editbox = self.browser.find_element_by_name('average_heart_rate')
self.assertIsNotNone(average_heart_rate_editbox)
# TODO: user sees km, bpm, .... next to the edit boxes
# user sees a submit button with the text 'submit' on it
submit_button = self.browser.find_element_by_id('submit_button')
self.assertEqual(submit_button.get_attribute('value'), 'submit')
# user enters data in the 4 fields an presses submit
# TODO : user sees he gets redirected to the same home url
distance_editbox.send_keys(distance)
executed_time_editbox.send_keys(executed_time)
in_zone_editbox.send_keys(in_zone)
average_heart_rate_editbox.send_keys(average_heart_rate)
submit_button.submit()
def check_entered_data_on_screen(self, data) :
# user sees a table and an entry in a table on the page with the entered data
try :
table_rows = self.browser.find_elements_by_tag_name('tr')
except StaleElementReferenceException :
# wait for all the elements to be attached to the DOM (stale exception selenium)
self.browser.implicitly_wait(3)
table_rows = self.browser.find_elements_by_tag_name('tr')
# user checks if the number of rows entered equals the number of rows displayed in the table
self.assertEqual(len(table_rows), len(data), 'not all data records are in the DB')
for table_row in table_rows :
self.assertIn(table_row.text, data, 'runners record wrong data or not in DB')
def test_enter_training_data(self) :
# user gets the url
self.browser.get(self.live_server_url)
# user enters a first set of data and checks if the data is receptioned by the system
self.user_sees_inputfields_and_enters_data('9', '00:46:48', '00:38:42', '162')
# user sees the row in the table on the page matching the data entered
self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162'])
# user enters a second set of data checks if the data is receptioned by the system
self.user_sees_inputfields_and_enters_data('14.182', '01:08:53', '00:52:23', '159')
# user sees both rows in the table on the page matching the data from the second training session
self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162', '14.182 1:08:53 0:52:23 159'])
# user closes the browser and reopens, to see his previously entered data
self.tearDown()
self.setUp()
# user gets the url
self.browser.get(self.live_server_url)
self.check_entered_data_on_screen(['9.0 0:46:48 0:38:42 162', '14.182 1:08:53 0:52:23 159'])
def test_web_page_is_loaded(self) :
# user gets the url
self.browser.get(self.live_server_url)
# user sees the title in the browser window
self.assertIn('Runners Log', self.browser.title)
示例9: RegistrationWebTest
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class RegistrationWebTest(TestCase):
"""
Test all facets of the registration process
"""
@classmethod
def clear_database(cls):
"""
Clear the database before and after use
"""
collection = cls.mongo.collection
for user in ['UnittestExistingTestUser', 'UnittestNonExistingTestUser']:
test_user = collection.find_one({
'username': user,
})
if test_user:
collection.remove(test_user)
@classmethod
def setUpClass(cls):
"""
Setup test data, browser and server
"""
cls.mongo = UserDatabaseConnectivity()
cls.clear_database()
test_user = {
'username': 'UnittestExistingTestUser',
'salt': '000',
'password': '000',
'enabled': False,
}
cls.mongo.collection.save(test_user)
cls.config = dict()
prepare_test(cls)
cls.base_url = 'http://{:s}:{:d}/static/index.xhtml'.format(cls.config['bind_ip'], cls.config['bind_port'])
@classmethod
def tearDownClass(cls):
"""
Disconnect from mongo and cleanup browser, server, etc.
"""
cls.clear_database()
del cls.mongo
cleanup(cls)
def setUp(self):
"""
Force a page refresh between tests
"""
self.webdriver = Firefox()
self.webdriver.implicitly_wait(10)
def tearDown(self):
"""
Throw test user out of database
"""
self.webdriver.close()
self.webdriver.quit()
collection = self.mongo.collection
test_user = collection.find_one({
'username': 'UnittestNonExistingTestUser',
})
if test_user:
collection.remove(test_user)
def __util_get_reg_button(self):
"""
Get the registration form button
"""
self.webdriver.get(self.base_url)
self.webdriver.implicitly_wait(10)
sleep(3)
button = self.webdriver.find_element_by_xpath('//xhtml:button[@data-formaction="registrationForm"]')
return button
def __util_open_dialog(self):
"""
Open the registration dialog
"""
button = self.__util_get_reg_button()
button.click()
self.webdriver.implicitly_wait(10)
sleep(5)
def test_find_button(self):
"""
Is the button there?
"""
self.assertIsNotNone(self.__util_get_reg_button())
def test_open_dialog(self):
"""
Can we open the dialog?
"""
dialog_xpath = '//xhtml:div[contains(@class, "bootstrap-dialog")]'
# Test that there is no dialog open at the moment
self.assertRaises(NoSuchElementException, self.webdriver.find_element_by_xpath, dialog_xpath)
self.__util_open_dialog()
dialog = self.webdriver.find_element_by_xpath(dialog_xpath)
self.assertIsNotNone(dialog)
#.........这里部分代码省略.........
示例10: webdriver
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
def webdriver(request):
driver = Firefox()
driver.get("http://www.12bet.com/")
driver.implicitly_wait(30)
request.addfinalizer(driver.quit)
return driver
示例11: init_webdriver
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
def init_webdriver(self):
driver = Firefox()
driver.implicitly_wait(20)
test_url = "http://%s:%s" % (self.ipaddr, self.port)
driver.get(test_url)
return driver
示例12: SeleniumTestCase
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
class SeleniumTestCase(LiveServerTestCase):
def setUp(self):
if _CI:
self.driver = self.sauce_chrome_webdriver()
elif settings.SELENIUM is True:
options = FirefoxOptions()
options.add_argument('-headless')
self.driver = Firefox(firefox_options=options)
self.driver.implicitly_wait(10)
def sauce_chrome_webdriver(self):
class_name = self.__class__.__name__
method_name = self._testMethodName
capabilities = {
'platform': "Mac OS X 10.10",
'browserName': "chrome",
'version': "37.0",
'name': '{}.{}'.format(class_name, method_name),
'tunnel-identifier': _TUNNEL_ID,
}
executor = "http://{}:{}@ondemand.saucelabs.com/wd/hub".format(
_SAUCE_USER,
_SAUCE_KEY,
)
return Remote(
command_executor=executor,
desired_capabilities=capabilities,
)
def tearDown(self):
self.driver.quit()
if _CI:
sauce_client = SauceClient(_SAUCE_USER, _SAUCE_KEY)
status = (sys.exc_info() == (None, None, None))
sauce_client.jobs.update_job(job_id=self.driver.session_id, build=_TUNNEL_ID,
passed=status)
def navigate(self, view_name: str):
path = reverse(view_name)
self.driver.get(self.live_server_url + path)
def assert_view(self, view_name: str):
path: str = self.driver.current_url.replace(self.live_server_url, '')
resolved: ResolverMatch = resolve(path)
self.assertEqual(resolved.view_name, view_name)
@contextmanager
def load(self, timeout=1):
page = self.driver.find_element_by_tag_name('html')
yield
WebDriverWait(self.driver, timeout).until(
staleness_of(page)
)
@contextmanager
def wait(self, timeout=1):
condition = _UrlHasChanged(self.driver.current_url)
yield
WebDriverWait(self.driver, timeout).until(condition)
示例13: RedFin
# 需要导入模块: from selenium.webdriver import Firefox [as 别名]
# 或者: from selenium.webdriver.Firefox import implicitly_wait [as 别名]
#.........这里部分代码省略.........
except:
property_data['beds'] = 'N/A';print('beds not found')
try:
property_data['baths'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-baths'}).find(
'div').get_text()
except:
property_data['baths'] = 'N/A';print('baths not found')
try:
property_data['sqFt'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-sqFt'}).find('span', attrs={
'class': 'main-font statsValue'}).get_text()
except:
property_data['sqFt'] = 'N/A';print('sqFt not found')
try:
property_data['price_per_sqFt'] = self.soup.find('div', attrs={'data-rf-test-id': 'abp-sqFt'}).find('div',
attrs={
"data-rf-test-id": "abp-priceperft"}).get_text()
except:
property_data['price_per_sqFt'] = 'N/A';print('price_per_sqFt not found')
try:
property_data['year_built'] = self.soup.find('span', attrs={"data-rf-test-id": "abp-yearBuilt"}).find(
'span', attrs={'class': 'value'}).get_text()
except:
property_data['year_built'] = 'N/A';print('year_built not found')
try:
property_data['days_on_redfin'] = self.soup.find('span',
attrs={"data-rf-test-id": "abp-daysOnRedfin"}).find('span',
attrs={
'class': 'value'}).get_text()
except:
property_data['days_on_redfin'] = 'N/A';print('days_on_redfin not found')
try:
property_data['status'] = self.soup.find('span', attrs={"data-rf-test-id": "abp-status"}).find('span',
attrs={
'class': 'value'}).get_text()
except:
property_data['status'] = 'N/A';print('status not found')
property_data['summary'] = self.soup.find('div', attrs={'class': 'remarks'}).get_text()
for row in self.soup.find('div', attrs={'class': 'more-info-div'}).find_all('tr'):
cells = row.find_all('td')
property_data[cells[0].get_text().strip()] = cells[1].get_text().strip()
# use loops to maintain data structure ina dict
property_data['property_details'] = OrderedDict()
for category in self.soup.find('div', attrs={'class': 'amenities-container'}).children:
key = category.contents[0].get_text().strip()
property_data['property_details'][key] = OrderedDict()
for row in category.contents[1].find_all('div', attrs={'class': 'amenity-group'}):
key2 = row.find('h4').get_text()
property_data['property_details'][key][key2] = []
for row2 in row.find_all('li'):
property_data['property_details'][key][key2].append(row2.get_text())
property_data['propert_history'] = []
for row in self.soup.find_all('tr', attrs={'id': reg_property_history_row}):
data_cells = row.find_all('td')
history_data_row = OrderedDict()
history_data_row['date'] = data_cells[0].get_text()
history_data_row['event & source'] = data_cells[1].get_text()
history_data_row['price'] = data_cells[2].get_text()
history_data_row['appreciation'] = data_cells[3].get_text()
property_data['propert_history'].append(history_data_row)
property_data['url'] = 'https://www.redfin.com' + property_url
self.output_data.append(property_data)
return property_data
def use_browser(self):
self.use_selenium = True
firefox_profile = FirefoxProfile()
# might as well turn off images since we don't need them
if self.use_proxies:
# if use proxies is true load firefox with proxies
firefox_profile.set_preference("permissions.default.image", 2)
proxy_host, proxy_port = choice(self.proxies).split(':')
firefox_profile.set_preference("network.proxy.type", 1)
firefox_profile.set_preference("network.proxy.http", proxy_host)
firefox_profile.set_preference("network.proxy.http_port", int(proxy_port))
firefox_profile.set_preference("network.proxy.ssl", proxy_host)
firefox_profile.set_preference("network.proxy.ssl_port", int(proxy_port))
self.driver = Firefox(firefox_profile)
self.driver.implicitly_wait(2)
def get_page_selenium(self, page_url):
self.driver.get(page_url)
self.selenium_bypass_captcha()
return self.driver.page_source
def selenium_bypass_captcha(self):
# basic code for handling captcha
# this requires the user to actually solve the captcha and then continue
try:
self.driver.switch_to_frame(self.driver.find_element_by_xpath('//iframe[@title="recaptcha widget"]'))
self.driver.find_element_by_class_name('recaptcha-checkbox-checkmark').click()
print('solve captcha ( pop up only ) and press enter to continue')
raw_input()
self.driver.switch_to_default_content()
self.driver.find_element_by_id('submit').click()
except Exception as e:
pass