本文整理汇总了Python中selenium.webdriver.support.expected_conditions.text_to_be_present_in_element_value函数的典型用法代码示例。如果您正苦于以下问题:Python text_to_be_present_in_element_value函数的具体用法?Python text_to_be_present_in_element_value怎么用?Python text_to_be_present_in_element_value使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_to_be_present_in_element_value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testExpectedConditionTextToBePresentInElementValue
def testExpectedConditionTextToBePresentInElementValue(self, driver, pages):
pages.load('booleanAttributes.html')
with pytest.raises(TimeoutException):
WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)")
WebDriverWait(driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
assert 'Example Expected text' == driver.find_element_by_id('inputRequired').get_attribute('value')
示例2: wait_updates
def wait_updates():
self.wait.until_not(EC.text_to_be_present_in_element_value(
(By.CLASS_NAME, 'js-cart-size'), ''
))
self.wait.until_not(EC.text_to_be_present_in_element_value(
(By.CLASS_NAME, 'js-mobile-cart-price'), ''
))
示例3: businessinsider_fetch_links
def businessinsider_fetch_links(string,driver):
check_sum=0
links_fetched = []
try:
driver.get('http://www.businessinsider.com/?IR=C')
check_sum=1
WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH,'/html/body/div[4]/div[1]/div/div[3]/div/ul[2]/div/li[3]/a[1]/i')))
except:
while check_sum==1:
try:
driver.get('http://www.businessinsider.com/?IR=C')
WebDriverWait(driver, 100).until(EC.element_to_be_clickable((By.XPATH,'/html/body/div[4]/div[1]/div/div[3]/div/ul[2]/div/li[3]/a[1]/i')))
check_sum=0
except:
print "Network Error... Trying to Reconnect!!!"
time.sleep(5)
try:
driver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div[3]/div/ul[2]/div/li[3]/a[1]/i').click()
except:
time.sleep(2)
driver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div[3]/div/ul[2]/div/li[3]/a[1]/i').click()
try:
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/form/input').send_keys('"'+string+'"',Keys.RETURN)
except:
driver.find_element_by_xpath('/html/body/div[4]/div[1]/div/div[3]/div/ul[2]/div/li[3]/a[1]/i').click()
time.sleep(2)
driver.find_element_by_xpath('/html/body/div[4]/div[2]/div/form/input').send_keys('"'+string+'"',Keys.RETURN)
try:
WebDriverWait(driver,1000).until(EC.text_to_be_present_in_element_value((By.XPATH,'//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3')))
driver.find_element_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3')
except:
time.sleep(10)
if driver.find_element_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3').text.split()[-2].strip()=='no':
driver.quit()
return []
elif driver.find_element_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3').text.split()[-2].strip().isalpha:
page=0
else:
page=int(driver.find_element_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3').text.split()[-2].strip())/20
while page>=0:
elem=driver.find_elements_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/div/div[2]/h3/a')
date=driver.find_elements_by_class_name('river-post__date')
for i,j in zip(elem,date):
i=i.get_attribute('href')
j=int(j.text.split(',')[1].strip())
if j<=2008 and i not in links_fetched:
links_fetched.append(i)
if page>0:
try:
driver.find_element_by_xpath('//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[2]/ul/li[2]/a').click()
WebDriverWait(driver,100).until(EC.text_to_be_present_in_element_value((By.XPATH,'//*[@id="main-content"]/div[2]/div/div/div/div[2]/div/div[2]/div[1]/h3')))
except:
'''Do Nothing...'''
page-=1
driver.quit()
return links_fetched
示例4: testExpectedConditionTextToBePresentInElementValue
def testExpectedConditionTextToBePresentInElementValue(self):
self._loadPage('booleanAttributes')
try:
WebDriverWait(self.driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
self.fail("Expected TimeoutException to have been thrown")
except TimeoutException as e:
pass
self.driver.execute_script("setTimeout(function(){document.getElementById('inputRequired').value = 'Example Expected text'}, 200)")
WebDriverWait(self.driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
self.assertEqual('Example Expected text', self.driver.find_element_by_id('inputRequired').get_attribute('value'))
示例5: wait_for_first_host_active
def wait_for_first_host_active(self, value):
xpath_loc = (
AmazonEc2Locators.Ec2Locators.STATUS_LABEL_PREFIX + "1" + AmazonEc2Locators.Ec2Locators.STATUS_LABEL_SUFFIX
)
print xpath_loc
element = self.driver.find_element(xpath_loc)
element = WebDriverWait(self.driver, 10).until(EC.text_to_be_present_in_element_value(element, value))
示例6: assert_element_text_value
def assert_element_text_value(self, how, what, text, message):
try:
return WebDriverWait(self.driver, 10).until(
EC.text_to_be_present_in_element_value((how, what), text)
)
except:
self.fail(message)
示例7: is_text_present_in_element
def is_text_present_in_element(locator, text, timeOut=0):
'''
Checking if the given text is present in the specified element\n
'''
try: _wait(timeOut).until(EC.text_to_be_present_in_element_value(Element(locator)._get(), text))
except WebDriverException: return False
return True
示例8: testExpectedConditionTextToBePresentInElementValue
def testExpectedConditionTextToBePresentInElementValue(self):
self._loadPage('booleanAttributes')
try:
WebDriverWait(self.driver, 1).until(EC.text_to_be_present_in_element_value((By.ID, 'inputRequired'), 'Expected'))
self.fail("Expected TimeoutException to have been thrown")
except TimeoutException, e:
pass
示例9: solve_captcha
async def solve_captcha(url, api, driver, timestamp):
driver.get(url)
WebDriverWait(driver, 86400).until(EC.text_to_be_present_in_element_value((By.NAME, "g-recaptcha-response"), ""))
driver.switch_to.frame(driver.find_element_by_xpath("//*/iframe[@title='recaptcha challenge']"))
token = driver.find_element_by_id("recaptcha-token").get_attribute("value")
request = api.create_request()
request.verify_challenge(token=token)
request.get_hatched_eggs()
request.get_inventory(last_timestamp_ms=timestamp)
request.check_awarded_badges()
request.get_buddy_walked()
request.check_challenge()
for attempt in range(-1, conf.MAX_RETRIES):
try:
response = await request.call()
return response['responses']['VERIFY_CHALLENGE']['success']
except (ex.HashServerException, ex.MalformedResponseException, ex.ServerBusyOrOfflineException) as e:
if attempt == conf.MAX_RETRIES - 1:
raise
else:
print('{}, trying again soon.'.format(e))
await sleep(4)
except ex.NianticThrottlingException:
if attempt == conf.MAX_RETRIES - 1:
raise
else:
print('Throttled, trying again in 11 seconds.')
await sleep(11)
except (KeyError, TypeError):
return False
示例10: test_submit_invalid_number
def test_submit_invalid_number(url):
"""
Example test using Selenium to submit an HTML form.
Assumption is that the result will display an error
if invalid input is submitted.
"""
driver = None
try:
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get(url)
input_field = driver.find_element_by_id('number')
button = driver.find_element_by_id('getFibNumber')
invalid_number = 'Hello world!'
input_field.send_keys(invalid_number)
button.click()
try:
wait.until(ec.text_to_be_present_in_element_value(
(By.ID,'number'),'Invalid number'))
except TimeoutException:
# Expected response not found, continue with assert
traceback.print_exc()
result = input_field.get_attribute('value')
assert result != invalid_number, 'No error message was displayed for invalid input'
except OSError as e:
#Firefox not installed, skip test
print "Skipping Selenium test, Firefox not installed/found"
finally:
if driver:
driver.quit()
示例11: test_submit_valid_number
def test_submit_valid_number(url):
"""
Example test using Selenium to submit an HTML form.
This assumes Firefox is installed. Asserts will be
skipped if Firefox cannot be found.
"""
driver = None
try:
driver = webdriver.Firefox()
wait = WebDriverWait(driver, 10)
driver.get(url)
input_field = driver.find_element_by_id('number')
button = driver.find_element_by_id('getFibNumber')
input_field.send_keys('4')
button.click()
try:
wait.until(ec.text_to_be_present_in_element_value((By.ID,'number'),'3'))
except TimeoutException:
# Expected response not found, continue with assert
traceback.print_exc()
assert input_field.get_attribute('value') == '3'
except OSError as e:
#Firefox not installed, skip test
print "Skipping Selenium test, Firefox not installed/found"
finally:
if driver:
driver.quit()
示例12: go_to_next_page
def go_to_next_page(driver,current_page):
next_button = driver.find_elements_by_id("MainContent_GridView1_ButtonNext")
if(len(next_button) == 0):
return 1
while True:
try:
next_button[0].click()
WebDriverWait(driver,100).until(
EC.text_to_be_present_in_element_value(
(By.ID,"MainContent_GridView1_PageCurrent"),`current_page+1`
)
)
break
except:
print("Took too long to go to the next page, going to click again")
return 0
示例13: get_stock_price
def get_stock_price(self, symbol):
symbol_input_xpath = "/html/body/form/table[3]/tbody/tr/td[1]/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/input"
refresh_xpath = "/html/body/form/table[3]/tbody/tr/td[1]/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[1]/td[2]/span/a"
price_xpath = "/html/body/form/table[3]/tbody/tr/td[1]/table/tbody/tr/td/table[2]/tbody/tr/td/table[1]/tbody/tr[4]/td[2]"
self.enter_stock_menu()
time.sleep(3)
self.select_menu_frame()
element = self.driver.find_element_by_xpath("/html/body/table[2]/tbody/tr[1]/td/a")
element.click()
time.sleep(3)
self.select_main_frame()
element = self.driver.find_element_by_xpath(symbol_input_xpath)
element.send_keys(symbol)
time.sleep(3)
element = self.driver.find_element_by_xpath(refresh_xpath)
element.click()
time.sleep(3)
# wait the price is not 0
WebDriverWait(self.driver, 10).until_not(
EC.text_to_be_present_in_element_value((By.XPATH, price_xpath), "0")
)
element = self.driver.find_element_by_xpath(price_xpath)
if element.text == "0":
self.logger.critical("Price is 0")
price = float(element.text)
return price
示例14: check_if_text_present_in_element_value
def check_if_text_present_in_element_value(webdriver, locator, text, message='text not present in element value',
timeout=2):
try:
WebDriverWait(webdriver, timeout).until(
expected_conditions.text_to_be_present_in_element_value(locator, text), message)
return True
except TimeoutException:
return False
示例15: step_impl
def step_impl(context):
button = context.browser.find_element_by_xpath('//*[@id="form_78ea690540a24bd8b9dcfbf99e999fea"]/div[1]/div[5]/input')
button.click()
try:
WebDriverWait(context.browser, 10).until(EC.text_to_be_present_in_element_value((By.ID, 'msg_78ea690540a24bd8b9dcfbf99e999fea'), 'Thank you sending us your information. We will get back to you with your Chai :)'))
except(Exception):
traceback.print_exc()
# context.browser.find_element_by_xpath('//*[@id="form_78ea690540a24bd8b9dcfbf99e999fea"]/div[1]/div[1]/input and @class="form-value form-value-invalid"')