本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait.submit方法的典型用法代码示例。如果您正苦于以下问题:Python WebDriverWait.submit方法的具体用法?Python WebDriverWait.submit怎么用?Python WebDriverWait.submit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui.WebDriverWait
的用法示例。
在下文中一共展示了WebDriverWait.submit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_first
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def parse_first(self, response):
query = response.meta['title'].decode('utf-8')
print query
try:
driver = response.webdriver
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input.search-combobox-input"))
)
# element = driver.find_element_by_css_selector("input#mq.s-combobox-input")
element.send_keys(query)
element.submit()
# wait for refresh
time.sleep(0.5)
for i in range(5):
product = response.webdriver.find_elements_by_css_selector("div.title a")
for e in product:
title = e.text.strip()
self.logger.info("query=%s, title=%s" % (query.encode('utf-8'), title.encode('utf-8')))
item = TitleSpiderItem()
item['title'] = title.encode('utf-8').replace(',', '')
item['query'] = query.encode('utf-8').replace(',', '')
yield item
# 点击下一页
self.logger.info("click")
with wait_for_page_load(driver):
driver.find_element_by_css_selector("div.mainsrp-pager a.J_Ajax").click()
except Exception, e:
self.logger.error(e)
示例2: test_simple_submit_scenario
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def test_simple_submit_scenario(self):
self.driver.get(self.server_url)
input_element = WebDriverWait(self.driver, 3).until(
EC.visibility_of_element_located((By.NAME, 'q')))
input_element.send_keys(self.id())
input_element.submit()
WebDriverWait(self.driver, 3).until(EC.title_is(self.id()))
示例3: test_create_posting_without_login
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def test_create_posting_without_login(self):
menu = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar")))
listing = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar #listing")))
actions = webdriver.ActionChains(self.driver)
actions.move_to_element(menu)
actions.click(listing)
actions.perform()
form_email = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "email")))
form_email.send_keys("s")
form_pass = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "password")))
form_pass.send_keys("s")
form_submit = self.driver.find_element_by_css_selector("#button")
form_submit.submit()
menu = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar")))
listing = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar #listing")))
actions = webdriver.ActionChains(self.driver)
actions.move_to_element(menu)
actions.click(listing)
actions.perform()
form_course = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "course_name")))
form_course.send_keys("s")
form_tag = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "tag")))
form_tag.send_keys("s")
form_desc = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#id_description")))
form_desc.send_keys("s")
form_qual = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "qualification")))
form_qual.send_keys("s")
form_times = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "times")))
form_times.send_keys("3:00 PM")
form_price = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "price")))
form_price.send_keys("30")
form_submit = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#button")))
form_submit.submit()
示例4: testSearch
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def testSearch(self):
'''test for course search with python keyword'''
driver = self.driver
searchXpath = "/html/body/div[3]/div/div[2]/div[1]/div[1]/nav/div/div[2]/span/form/span/span/input[2]"
searchElement = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_xpath(searchXpath))
searchElement.send_keys("python")
searchElement.submit()
示例5: scrape_namechar_stat
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def scrape_namechar_stat(self, korchar):
try:
searchbox_id = 'ctl00_ContentPlaceHolder1_idSearchBox'
searchbox = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, searchbox_id)))
name = ''.join(['김', korchar, korchar])
script = "document.getElementById('%s').value='%s';" % (searchbox_id, name.decode('utf-8'))
self.driver.execute_script(script)
searchbox.submit()
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'name_info')))
except TimeoutException:
raise
soup = BS(self.driver.page_source, 'html.parser')
name_info = soup.find(id="name_info")
char_info_text = name_info.find_all('table')[3].find('tbody').find('tr').find('td').text
infos = char_info_text.encode('utf-8').strip().replace('%','').split('\n')
infos = [line.strip() for line in infos]
m_rank = re.findall('(?<=\s)[0-9]*(?=번째)', infos[0])[0]
m_portion = re.findall('(?<=\()[0-9.]*(?=\))', infos[0])[0]
[m1_rank, m2_rank] = re.findall('(?<=\s)[0-9]*(?=번째)', infos[1])
[m1_portion, m2_portion] = re.findall('(?<=\()[0-9.]*(?=\))', infos[1])
f_rank = re.findall('(?<=\s)[0-9]*(?=번째)', infos[3])[0]
f_portion = re.findall('(?<=\()[0-9.]*(?=\))', infos[3])[0]
[f1_rank, f2_rank] = re.findall('(?<=\s)[0-9]*(?=번째)', infos[4])
[f1_portion, f2_portion] = re.findall('(?<=\()[0-9.]*(?=\))', infos[4])
namechar = NameChar(korchar, m_rank, m_portion, m1_rank, m1_portion, m2_rank, m2_portion, f_rank, f_portion, f1_rank, f1_portion, f2_rank, f2_portion)
return namechar
示例6: login
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def login(self, authentication=None):
"""
authentication: path to authentication json file
"""
self._driver.get(urljoin(HOST, "accounts/login/"))
if authentication:
print("Username and password loaded from {}".format(authentication))
with open(authentication, 'r') as fin:
auth_dict = json.loads(fin.read())
# Input username
username_input = WebDriverWait(self._driver, 5).until(
EC.presence_of_element_located((By.NAME, 'username'))
)
username_input.send_keys(auth_dict['username'])
# Input password
password_input = WebDriverWait(self._driver, 5).until(
EC.presence_of_element_located((By.NAME, 'password'))
)
password_input.send_keys(auth_dict['password'])
# Submit
password_input.submit()
else:
print("Type your username and password by hand to login!")
print("You have a minute to do so!")
print("")
WebDriverWait(self._driver, 60).until(
EC.presence_of_element_located((By.CSS_SELECTOR, CSS_EXPLORE))
)
示例7: try_login
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def try_login(driver, username, password):
elem = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_name("username"))
elem.send_keys(username)
elem = WebDriverWait(driver, 10).until(
lambda driver: driver.find_element_by_name("password"))
elem.send_keys(password)
elem.submit()
示例8: scrape
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def scrape(self, is_surname):
if is_surname:
with open("surname.csv", 'r') as f:
lines = f.readlines()
namechars = [line.split(',')[0] for line in lines]
# namechars = ['김', '범']
sqldb = StoreSurname('surname')
else:
with open("kornamechar.txt", 'r') as f:
lines = f.readlines()
namechars = [line.strip() for line in lines]
sqldb = StoreNameChar('namechar')
self.driver.get('http://s.lab.naver.com/translation/')
print self.driver.title
conversion = dict()
for char in namechars:
try:
querybox = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'query')))
name = char if is_surname else ' '.join(['김', char])
script = "document.getElementById('%s').value='%s';" % ('query', name)
self.driver.execute_script(script)
querybox.submit()
table = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, 'engname_popular')))
soup = BS(table.get_attribute('innerHTML'), 'html.parser')
trs = soup.find('tbody').find_all('tr')
engchars = dict()
for tr in trs:
engname = tr.find('td', {'class': 'cell_engname'}).text
engchar = engname.strip() if is_surname else engname.split()[1]
percent = tr.find('td', {'class': 'cell_frequency'}).find('img')['alt']
freq = float(percent.replace('%', ''))
engchars[engchar.lower()] = freq
freq_sum = sum(engchars.values())
for engchar in engchars:
engchars[engchar] = round(engchars[engchar] / freq_sum, 4)
if is_surname:
keyboard_position = get_position(char)
sqldb.set(char, keyboard_position, engchars)
else:
sqldb.set_engchars(char, engchars)
print char, engchars
conversion[char] = engchars
except TimeoutException:
print "%s is not scraped" % char
continue
sqldb.commit()
sqldb.close()
return conversion
示例9: testInput
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def testInput(self):
email = WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.ID, "Email")))
email.send_keys(self.email)
pw = WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.ID, "Passwd")))
pw.send_keys(self.ps)
self.assertIn('Gmail', self.browser.title)
ele_submit = WebDriverWait(self.browser, 10).until(EC.presence_of_element_located((By.ID, "signIn")))
ele_submit.submit()
time.sleep(5)
self.assertTrue(self.browser.current_url.startswith('https://mail.google.com/mail/'))
示例10: login
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def login(driver):
driver.get('https://drive.google.com')
email_box = driver.find_element_by_id('Email')
email_box.send_keys(EMAIL_ID)
email_box.submit()
password_box = WebDriverWait(driver, MAX_WAIT_TIME_SECONDS).until(
expected_conditions.presence_of_element_located((By.ID, 'Passwd'))
)
password_box.send_keys(PASSWORD)
password_box.submit()
wait_until_load(driver)
示例11: parse
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def parse(self, response):
browser = webdriver.Firefox()
browser.implicitly_wait(FoscamSpider.timeout)
browser.set_page_load_timeout(FoscamSpider.timeout)
t = FoscamSpider.trytimes
while 1:
try:
try:
browser.get(response.url)
except TimeoutException:
pass
try:
login_button = WebDriverWait(browser, FoscamSpider.timeout).until(
EC.presence_of_element_located((By.XPATH, "//div[@class='reg_click']/form/a")))
except TimeoutException:
login_button = browser.find_element_by_xpath(
"//div[@class='reg_click']/form/a")
try:
login_button.click()
except TimeoutException:
pass
try:
email = WebDriverWait(browser, FoscamSpider.timeout).until(EC.presence_of_element_located(
(By.XPATH, "//div[@class='login_click']//input[@class='email']")))
except TimeoutException:
login_button.click()
email = browser.find_element_by_xpath(
"//div[@class='login_click']//input[@class='email']")
email.send_keys("[email protected]")
email.submit()
try:
success = WebDriverWait(browser, FoscamSpider.timeout).until(
EC.presence_of_element_located((By.ID, "tpl_main")))
except TimeoutException:
pass
except Exception, e:
t -= 1
logging.log(logging.WARNING, "Login failed, Try again(%d):%s",
FoscamSpider.trytimes - t, e.message)
if t == 0:
logging.exception(e)
browser.quit()
return
else:
break
示例12: scrape_name_stat
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def scrape_name_stat(self, name):
try:
searchbox_id = 'ctl00_ContentPlaceHolder1_idSearchBox'
searchbox = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, searchbox_id)))
fullname = ''.join(['김', name])
script = "document.getElementById('%s').value='%s';" % (searchbox_id, fullname.decode('utf-8'))
self.driver.execute_script(script)
searchbox.submit()
WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.ID, 'name_info')))
except TimeoutException:
raise
soup = BS(self.driver.page_source, 'html.parser')
name_info = soup.find(id="name_info")
namestat_trs = name_info.find_all('table')[1].find('tbody').find_all('tr')
preference = namestat_trs[0].find('td').text.encode('utf-8').strip()
gender_likely = namestat_trs[2].find('td').text.encode('utf-8').strip()
birth_info = namestat_trs[3].find('td').text.encode('utf-8').strip()
gender_likely_lines = gender_likely.split('\n')
gender_likely_line2 = gender_likely_lines[2].strip()
gender_likely_line3 = gender_likely_lines[3].strip()
prob = re.findall('(?<=\s)[0-9.]*(?=%)', gender_likely_line2)[0]
gender = re.findall('(?<=\s)[가-힣]*(?=성적인)', gender_likely_line2)[0]
m_freq, f_freq = re.findall('(?<=\s)[0-9,]*(?=번)', gender_likely_line3)
if gender == '남':
f_p = 1 - float(prob)/100
elif gender == '여':
f_p = float(prob)/100
else:
return None
m_freq = int(m_freq.replace(',', ''))
f_freq = int(f_freq.replace(',', ''))
rank = safe_list_get(re.findall('(?<=\s)[0-9]*(?=번째)', preference), 0, '-1')
rank = int(rank.replace(',', ''))
proportion = float(safe_list_get(re.findall('(?<=\()[0-9.]*(?=%)', preference), 0, 0))
freq_year = int(re.findall('(?<=\s)[0-9]*(?=년도에)', birth_info)[0])
freq_region = re.findall('(?<=\s)[가-힣]*(?=\s출생인)', birth_info)[0]
freq_sur = re.findall('(?<=\s)[가-힣]*(?=씨입니다)', preference)[0]
namestat = NameStat(name, rank, proportion, f_p, m_freq, f_freq, freq_year, freq_region, freq_sur)
return namestat
示例13: parse_first
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def parse_first(self, response):
# 编码问题trick
query = response.meta['title'].decode('utf-8')
print query
try:
driver = response.webdriver
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input#mq.s-combobox-input"))
)
#element = driver.find_element_by_css_selector("input#mq.s-combobox-input")
element.send_keys(query)
element.submit()
#wait for refresh
time.sleep(0.5)
for i in range(5):
#js = "window.scrollTo(100,10000)"
#driver.execute_script(js)
# 等待一下dom才加载完毕, 所以这个步骤也许会失败吧
product = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.CSS_SELECTOR, "p.productTitle a"))
)
#product = response.webdriver.find_elements_by_css_selector("p.productTitle a")
for e in product:
title = e.text.strip()
self.logger.info("query=%s, title=%s" % (query.encode('utf-8'), title.encode('utf-8')))
item = TitleSpiderItem()
item['title'] = title.encode('utf-8').replace(',', '')
item['query'] = query.encode('utf-8').replace(',', '')
yield item
# 点击下一页
self.logger.info("click")
with wait_for_page_load(driver):
driver.find_element_by_css_selector("a.ui-page-next").click()
except Exception, e:
self.logger.error(e)
traceback.print_exc()
示例14: test_asignup
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
def test_asignup(self):
menu = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar")))
signup = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, ".navbar #signup")))
actions = webdriver.ActionChains(self.driver)
actions.move_to_element(menu)
actions.click(signup)
actions.perform()
form_name = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "name")))
form_name.send_keys("s")
form_user = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "email")))
form_user.send_keys("s")
form_pass = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "password")))
form_pass.send_keys("s")
form_phone = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.NAME, "phone")))
form_phone.send_keys("s")
form_desc = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#id_description")))
form_desc.send_keys("s")
form_submit = WebDriverWait(self.driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "#button")))
form_submit.submit()
示例15: WebDriverWait
# 需要导入模块: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
# 或者: from selenium.webdriver.support.ui.WebDriverWait import submit [as 别名]
elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.lang-chooser"))
)
if handle in elem.text:
return
else:
print "Invalid handle or password!"
login()
if 'Enter' in elem.text :
login()
try:
while True:
elem=driver.find_element_by_class_name("datatable")
elem.find_element_by_partial_link_text('Register').click()
elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "input.submit"))
)
elem.submit()
elem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "div.lang-chooser"))
)
except NoSuchElementException :
print 'Error occured. please enable firebug and debug.'
pass
finally:
print 'All Done.'
#driver.close()