本文整理匯總了Python中selenium.webdriver.common.by.By.ID屬性的典型用法代碼示例。如果您正苦於以下問題:Python By.ID屬性的具體用法?Python By.ID怎麽用?Python By.ID使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類selenium.webdriver.common.by.By
的用法示例。
在下文中一共展示了By.ID屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: submit_user_data
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def submit_user_data(self):
# Submit to Authent-Number Page (press button).
wait = WebDriverWait(self.driver, timeout=6)
try:
self.driver.execute_script(
'document.getElementsByTagName("button")[0].click()'
)
wait.until(
EC.presence_of_element_located(
(By.ID, 'idRandomPic')
)
)
except:
self.label_show_result.setText(
'【連線逾時或是網路不穩定】\n' +
'【請檢查網路環境以及是否為尖峰時段。】'
)
示例2: index_page
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def index_page(page):
try:
print('正在爬取第: %s 頁' % page)
wait.until(
EC.presence_of_element_located((By.ID, "dt_1")))
# 判斷是否是第1頁,如果大於1就輸入跳轉,否則等待加載完成。
if page > 1:
# 確定頁數輸入框
input = wait.until(EC.presence_of_element_located(
(By.XPATH, '//*[@id="PageContgopage"]')))
input.click()
input.clear()
input.send_keys(page)
submit = wait.until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, '#PageCont > a.btn_link')))
submit.click()
time.sleep(2)
# 確認成功跳轉到輸入框中的指定頁
wait.until(EC.text_to_be_present_in_element(
(By.CSS_SELECTOR, '#PageCont > span.at'), str(page)))
except Exception:
return None
示例3: __login
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def __login(self):
if self.debug: self.driver.save_screenshot(self.directory + r'01.png')
txt_login = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtLogin')
txt_login.clear()
txt_login.send_keys(os.environ['CPF'])
time.sleep(3.0)
txt_senha = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_txtSenha')
txt_senha.clear()
txt_senha.send_keys(os.environ['SENHA_CEI'])
time.sleep(3.0)
if self.debug: self.driver.save_screenshot(self.directory + r'02.png')
btn_logar = self.driver.find_element_by_id('ctl00_ContentPlaceHolder1_btnLogar')
btn_logar.click()
try:
WebDriverWait(self.driver, 60).until(EC.visibility_of_element_located((By.ID, 'objGrafPosiInv')))
except Exception as ex:
raise Exception('Nao foi possivel logar no CEI. Possivelmente usuario/senha errada ou indisponibilidade do site')
if self.debug: self.driver.save_screenshot(self.directory + r'03.png')
示例4: __recupera_tipo_ticker
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def __recupera_tipo_ticker(self):
WebDriverWait(CrawlerAdvfn.driver, 10).until(EC.visibility_of_element_located((By.ID, 'quoteElementPiece5')))
tipo = CrawlerAdvfn.driver.find_element_by_id('quoteElementPiece5').text.lower()
if tipo == 'futuro':
return TipoTicker.FUTURO
if tipo == 'opção':
return TipoTicker.OPCAO
if tipo == 'preferencial' or tipo == 'ordinária':
return TipoTicker.ACAO
if tipo == 'fundo':
if self.__fundo_eh_fii():
return TipoTicker.FII
if self.__fundo_eh_etf():
return TipoTicker.ETF
return None
示例5: participate
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def participate(self):
random.seed(self.worker_id)
chatbot = random.choice(self.PERSONALITIES)
WebDriverWait(self.driver, 10).until(
EC.element_to_be_clickable((By.ID, "send-message"))
)
logger.info("Entering participate method")
start = time.time()
while (time.time() - start) < self.TOTAL_CHAT_TIME:
self.wait_to_send_message()
history = self.get_chat_history()
logger.info("History: %s" % history)
if history and history[-1]:
logger.info("Responding to: %s" % history[-1])
output = chatbot.respond(history[-1])
else:
logger.info("Using random greeting.")
output = random.choice(self.GREETINGS)
logger.info("Output: %s" % output)
self.send_message(output)
self.leave_chat()
示例6: sign_off
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def sign_off(self):
"""Submit questionnaire and finish.
This uses Selenium to click the submit button on the questionnaire
and return to the original window.
"""
try:
logger.info("Bot player signing off.")
feedback = WebDriverWait(self.driver, 20).until(
EC.presence_of_element_located((By.ID, "submit-questionnaire"))
)
self.complete_questionnaire()
feedback.click()
logger.info("Clicked submit questionnaire button.")
self.driver.switch_to_window(self.driver.window_handles[0])
self.driver.set_window_size(1024, 768)
logger.info("Switched back to initial window.")
return True
except TimeoutException:
logger.error("Error during experiment sign off.")
return False
示例7: wait_for_text
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def wait_for_text(driver, el_id, value, removed=False, timeout=10):
el = wait_for_element(driver, el_id, timeout)
if value in el.text and not removed:
return el
if removed and value not in el.text:
return el
wait = WebDriverWait(driver, timeout)
condition = EC.text_to_be_present_in_element((By.ID, el_id), value)
if removed:
wait.until_not(condition)
if value not in el.text:
return el
else:
wait.until(condition)
if value in el.text:
return el
raise AttributeError
示例8: test_08_invalid_trans_id
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def test_08_invalid_trans_id(self, base_url, selenium):
self.get(selenium, base_url + '/reconcile')
assert self.get_reconciled(selenium) == {}
script = 'reconciled[1234] = [4, "OFXNONE"];'
selenium.execute_script(script)
assert self.get_reconciled(selenium) == {
1234: [4, "OFXNONE"]
}
# click submit button
selenium.find_element_by_id('reconcile-submit').click()
sleep(1)
self.wait_for_jquery_done(selenium)
assert self.get_reconciled(selenium) == {
1234: [4, "OFXNONE"]
}
msg = selenium.find_element_by_id('reconcile-msg')
assert msg.text == 'Error 400: Invalid Transaction ID: 1234'
assert 'alert-danger' in msg.get_attribute('class')
示例9: wait_until_clickable
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def wait_until_clickable(self, driver, elem_id, by=By.ID, timeout=10):
"""
Wait for the modal to be shown.
:param driver: Selenium driver instance
:type driver: selenium.webdriver.remote.webdriver.WebDriver
:param elem_id: element ID
:type elem_id: str
:param by: What method to use to find the element. This must be one of
the strings which are values of
:py:class:`selenium.webdriver.common.by.By` attributes.
:type by: str
:param timeout: timeout in seconds
:type timeout: int
"""
WebDriverWait(driver, timeout).until(
EC.element_to_be_clickable((by, elem_id))
)
示例10: SwitchModal
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def SwitchModal(self, option, frame=''):
'''
Sets the focus in a modal object
'''
try:
time.sleep(2)
self.driver.switch_to.default_content()
self.driver.implicitly_wait(30)
modaldupGuia = self.wait.until(EC.presence_of_element_located((By.ID, "modal-content")))
if modaldupGuia.is_displayed():
btn = self.driver.find_element_by_xpath("//button[contains(text(), '%s')]" % option)
btn.click()
else:
time.sleep(2)
if modaldupGuia.is_displayed():
btn = self.driver.find_element_by_xpath("//button[contains(text(), '%s')]" % option)
btn.click()
except Exception as e:
self.log_error(str(e))
示例11: get_web_value
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def get_web_value(self, element):
"""
Gets the informations of field based in the ID
"""
if element.tag_name == "div":
element_children = element.find_element(By.CSS_SELECTOR, "div > * ")
if element_children is not None:
element = element_children
if element.tag_name == "label":
web_value = element.get_attribute("text")
elif element.tag_name == "select":
current_select = int(element.get_attribute('value'))
selected_element = element.find_elements(By.CSS_SELECTOR, "option")[current_select]
web_value = selected_element.text
else:
web_value = element.get_attribute("value")
return web_value
示例12: start_captcha
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def start_captcha():
driver = webdriver.Firefox()
driver.get("http://reddit.com")
driver.find_element(By.XPATH, "//*[@id=\"header-bottom-right\"]/span[1]/a").click()
time.sleep(1)
driver.find_element(By.ID, "user_reg").send_keys("qwertyuiop091231")
driver.find_element(By.ID, "passwd_reg").send_keys("THISISMYPASSWORD!!$")
driver.find_element(By.ID, "passwd2_reg").send_keys("THISISMYPASSWORD!!$")
driver.find_element(By.ID, "email_reg").send_keys("biggie.smalls123@gmail.com")
#driver.find_element_by_tag_name("body").send_keys(Keys.COMMAND + Keys.ALT + 'k')
iframeSwitch = driver.find_element(By.XPATH, "//*[@id=\"register-form\"]/div[6]/div/div/div/iframe")
driver.switch_to.frame(iframeSwitch)
driver.find_element(By.ID, "recaptcha-anchor").click()
# download captcha image
#
# split payload
#
# reverse_search
#
# driver.quit()
# determines if an image keywords matches the target keyword
# uses the synonyms of the image keyword
示例13: close_letter
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def close_letter(self):
# If we are at specific letter, press the "go back" button.
elems = self.worker.all(By.CSS_SELECTOR, '.pageTitle')
if len(elems) != 0:
title = elems[0].text.strip()
if title == 'Configuration File':
try:
backBtn = self.worker.first(By.ID, 'PAGE_BUTTONS_cbuttonback')
backBtn.click()
except NoSuchElementException:
pass
try:
backBtn = self.worker.first(By.ID, 'PAGE_BUTTONS_cbuttonnavigationcancel')
backBtn.click()
except NoSuchElementException:
pass
self.worker.wait_for(By.CSS_SELECTOR, '#TABLE_DATA_fileList')
示例14: pass_check
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def pass_check(self):
no_7 = self.driver.find_element(value="digit_7", by=By.ID)
no_7.click();
plus = self.driver.find_element(value="op_add", by=By.ID)
plus.click();
no_4 = self.driver.find_element(value="digit_4", by=By.ID)
no_4.click();
equalTo = self.driver.find_element(value="eq", by=By.ID)
equalTo.click();
results = self.driver.find_element(value="formula", by=By.ID)
result_value = results.get_attribute('text')
if result_value == '11':
self.passed('Value is 11')
else:
self.failed('Value is not 11')
# Second test section
示例15: failure_check
# 需要導入模塊: from selenium.webdriver.common.by import By [as 別名]
# 或者: from selenium.webdriver.common.by.By import ID [as 別名]
def failure_check(self):
no_7 = self.driver.find_element(value="digit_7", by=By.ID)
no_7.click();
plus = self.driver.find_element(value="op_add", by=By.ID)
plus.click();
no_4 = self.driver.find_element(value="digit_4", by=By.ID)
no_4.click();
equalTo = self.driver.find_element(value="eq", by=By.ID)
equalTo.click();
results = self.driver.find_element(value="formula", by=By.ID)
result_value = results.get_attribute('text')
if result_value == '12':
self.passed('Value is 12')
else:
self.failed('Value is not 12')