本文整理汇总了Python中selenium.webdriver.support.ui.WebDriverWait方法的典型用法代码示例。如果您正苦于以下问题:Python ui.WebDriverWait方法的具体用法?Python ui.WebDriverWait怎么用?Python ui.WebDriverWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.ui
的用法示例。
在下文中一共展示了ui.WebDriverWait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: submit_user_data
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [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: _wait_until
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def _wait_until(self, condition_method, condition_input, timeout=None):
"""
Common method to wait until condition met
:param condition_method: method to check the condition
:param condition_input: parameter that will be passed to the condition method
:param timeout: max time to wait
:returns: condition method response
"""
# Remove implicitly wait timeout
implicitly_wait = self.get_implicitly_wait()
if implicitly_wait != 0:
self.driver_wrapper.driver.implicitly_wait(0)
try:
# Get explicitly wait timeout
timeout = timeout if timeout else self.get_explicitly_wait()
# Wait for condition
condition_response = WebDriverWait(self.driver_wrapper.driver, timeout).until(
lambda s: condition_method(condition_input))
finally:
# Restore implicitly wait timeout from properties
if implicitly_wait != 0:
self.set_implicitly_wait()
return condition_response
示例3: crack
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def crack(self):
true_image = self.get_true_image()
x_offset = self.analysis(true_image)
print(x_offset)
track = self.get_track(x_offset)
knob_element = WebDriverWait(self.driver, 50).until(
EC.element_to_be_clickable((By.XPATH, r'/html/body/div[2]/div[2]/div[6]/div/div[1]/div[2]/div[2]')))
self.move_to_gap(knob_element, track)
# fn = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result0.png')
# fn1 = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'result1.png')
# time.sleep(0.02)
# screen_shot = self.driver.save_screenshot(fn)
# time.sleep(2)
# screen_shot = self.driver.save_screenshot(fn1)
示例4: login
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def login(driver, user, password):
wait = WebDriverWait(driver, 10)
driver.get(
'https://www.odoo.com/web/login?redirect=%2Foauth2%2Fauth%2F%3Fscope'
'%3Duserinfo%26redirect_uri%3Dhttps%253A%252F%252Fapps.odoo.com%252F'
'auth_oauth%252Fsignin%26state%3D%257B%2522p%2522%253A%2B1%252C%2B'
'%2522r%2522%253A%2B%2522%25252F%25252Fapps.odoo.com%25252Fapps%25'
'22%252C%2B%2522d%2522%253A%2B%2522apps%2522%257D%26response_type%3D'
'token%26client_id%3Da0a30d16-6095-11e2-9c70-002590a17fd8&scope=user'
'info&mode=login&redirect_hostname=https%3A%2F%2Fapps.odoo.com&login='
)
login_field = driver.find_element_by_id('login')
login_field.clear()
login_field.send_keys(user)
password_field = driver.find_element_by_id('password')
password_field.clear()
password_field.send_keys(password)
login_button = driver.find_element_by_xpath(
'.//form[@action="/web/login"]//button[@type="submit"]'
)
login_button.click()
wait.until(
lambda driver: driver.current_url == 'https://apps.odoo.com/apps'
)
示例5: __login
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [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')
示例6: __init__
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def __init__(self):
self.browse = None
self.source_playlist = None
self.target_playlist_tag = None
self.success_list = list()
self.failed_list = list()
os.environ["webdriver.chrome.driver"] = chrome_driver_path
os.environ["webdriver.phantomjs.driver"] = phantomjs_driver_path
# chromedriver = chrome_driver_path
phantomjs_driver = phantomjs_driver_path
opts = Options()
opts.add_argument("user-agent={}".format(headers["User-Agent"]))
# browser = webdriver.Chrome(chromedriver)
browser = webdriver.PhantomJS(phantomjs_driver)
self.browser = browser
self.wait = ui.WebDriverWait(self.browser, 5)
self.config = Config()
示例7: wait_for_element
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def wait_for_element(driver: 'WebDriver', locator: str, value: str, timeout: int = SLEEPY_TIME) -> 'WebElement':
"""Wait until the element located
Args:
driver: WebDriver instance
locator: Locator like WebDriver, Mobile JSON Wire Protocol
(e.g. `appium.webdriver.common.mobileby.MobileBy.ACCESSIBILITY_ID`)
value: Query value to locator
timeout: Maximum time to wait the element. If time is over, `TimeoutException` is thrown
Raises:
`selenium.common.exceptions.TimeoutException`
Returns:
The found WebElement
"""
return WebDriverWait(driver, timeout).until(
EC.presence_of_element_located((locator, value))
)
示例8: sign_off
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [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
示例9: wait_for_text
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [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
示例10: click_tiles
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def click_tiles(driver, coords):
orig_srcs, new_srcs = {}, {}
for (x, y) in coords:
logging.debug("[*] Going to click {} {}".format(x,y))
tile1 = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//div[@id="rc-imageselect-target"]/table/tbody/tr[{0}]/td[{1}]'.format(x, y))))
orig_srcs[(x, y)] = driver.find_element(By.XPATH, "//*[@id=\"rc-imageselect-target\"]/table/tbody/tr[{}]/td[{}]/div/div[1]/img".format(x,y)).get_attribute("src")
new_srcs[(x, y)] = orig_srcs[(x, y)] # to check if image has changed
tile1.click()
wait_between(0.1, 0.5)
logging.debug("[*] Downloading new inbound image...")
new_files = {}
for (x, y) in orig_srcs:
while new_srcs[(x, y)] == orig_srcs[(x, y)]:
new_srcs[(x, y)] = driver.find_element(By.XPATH, "//*[@id=\"rc-imageselect-target\"]/table/tbody/tr[{}]/td[{}]/div/div[1]/img".format(x,y)).get_attribute("src")
time.sleep(0.5)
urllib.urlretrieve(new_srcs[(x, y)], "captcha.jpeg")
new_path = TASK_PATH+"/new_output{}{}.jpeg".format(x, y)
os.system("mv captcha.jpeg "+new_path)
new_files[(x, y)] = (new_path)
return new_files
示例11: test_stick_to_top_admin
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def test_stick_to_top_admin(self):
self.browser.get(self.live_server_url + reverse("niji:index"))
login(self.browser, 'super', '123')
self.assertIn("Log out", self.browser.page_source)
lucky_topic1 = getattr(self, 't%s' % random.randint(1, 50))
self.browser.get(self.live_server_url+reverse('niji:topic', kwargs={"pk": lucky_topic1.pk}))
self.browser.find_element_by_class_name('move-topic-up').click()
up_level = WebDriverWait(
self.browser, 10
).until(
expected_conditions.presence_of_element_located(
(By.NAME, 'move-topic-up-level')
)
)
up_level = Select(up_level)
up_level.select_by_visible_text('1')
time.sleep(1)
self.browser.execute_script("$('.modal-confirm').click()")
self.browser.get(self.live_server_url+reverse('niji:index'))
first_topic_title = self.browser.find_elements_by_class_name('entry-link')[0].text
self.assertEqual(first_topic_title, lucky_topic1.title)
示例12: Single_Issue
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def Single_Issue(url,Quality):
#print url
print 'Quality To Download : ',Quality[0]
print 'Order To Download : ',Quality[1]
#sys.exit()
#print url,' This is first'
browser = webdriver.PhantomJS(service_args=['--load-images=no'])
browser.get(url)
try:
element = WebDriverWait(browser, 10).until(
EC.presence_of_element_located((By.ID, "stSegmentFrame"))
)
#print 'Downloading the whole page! Will take some time, please don\'t close this script...\n'
#print 'I\'ve waited long enough'
except Exception, e:
#raise e
browser.save_screenshot('Single_exception.png')
print e
pass
示例13: __init__
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def __init__(self, wait, screenshot=None, session=None):
chrome_options = Options()
if session:
chrome_options.add_argument("--user-data-dir={}".format(session))
self.browser = webdriver.Chrome(options=chrome_options) # we are using chrome as our webbrowser
else:
self.browser = webdriver.Chrome()
self.browser.get("https://web.whatsapp.com/")
# emoji.json is a json file which contains all the emojis
with open("emoji.json") as emojies:
self.emoji = json.load(emojies) # This will load the emojies present in the json file into the dict
WebDriverWait(self.browser,wait).until(EC.presence_of_element_located(
(By.CSS_SELECTOR, '._3FRCZ')))
if screenshot is not None:
self.browser.save_screenshot(screenshot) # This will save the screenshot to the specified file location
# This method is used to send the message to the individual person or a group
# will return true if the message has been sent, false else
示例14: send_message
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def send_message(self, name, message):
message = self.emojify(message) # this will emojify all the emoji which is present as the text in string
search = self.browser.find_element_by_css_selector("._3FRCZ")
search.send_keys(name+Keys.ENTER) # we will send the name to the input key box
try:
send_msg = WebDriverWait(self.browser, self.timeout).until(EC.presence_of_element_located(
(By.XPATH, "/html/body/div/div/div/div[4]/div/footer/div[1]/div[2]/div/div[2]")))
messages = message.split("\n")
for msg in messages:
send_msg.send_keys(msg)
send_msg.send_keys(Keys.SHIFT+Keys.ENTER)
send_msg.send_keys(Keys.ENTER)
return True
except TimeoutException:
raise TimeoutError("Your request has been timed out! Try overriding timeout!")
except NoSuchElementException:
return False
except Exception:
return False
# This method will count the no of participants for the group name provided
示例15: get_last_seen
# 需要导入模块: from selenium.webdriver.support import ui [as 别名]
# 或者: from selenium.webdriver.support.ui import WebDriverWait [as 别名]
def get_last_seen(self, name, timeout=10):
search = self.browser.find_element_by_css_selector("._3FRCZ")
search.send_keys(name+Keys.ENTER) # we will send the name to the input key box
last_seen_css_selector = "._315-i"
start_time = dt.datetime.now()
try:
WebDriverWait(self.browser,self.timeout).until(EC.presence_of_element_located(
(By.CSS_SELECTOR, last_seen_css_selector)))
while True:
last_seen = self.browser.find_element_by_css_selector(last_seen_css_selector).text
if last_seen and "click here" not in last_seen:
return last_seen
end_time = dt.datetime.now()
elapsed_time = (end_time-start_time).seconds
if elapsed_time > 10:
return "None"
except TimeoutException:
raise TimeoutError("Your request has been timed out! Try overriding timeout!")
except NoSuchElementException:
return "None"
except Exception:
return "None"
# This method does not care about anything, it sends message to the currently active chat
# you can use this method to recursively send the messages to the same person