本文整理汇总了Python中selenium.webdriver.support.wait.WebDriverWait方法的典型用法代码示例。如果您正苦于以下问题:Python wait.WebDriverWait方法的具体用法?Python wait.WebDriverWait怎么用?Python wait.WebDriverWait使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类selenium.webdriver.support.wait
的用法示例。
在下文中一共展示了wait.WebDriverWait方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wait_until_impl
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_impl(self, condition_fn, timeout_secs=10, interval_secs=0.5):
if ismethod(condition_fn):
is_bound = condition_fn.__self__ is not None
args_spec = getfullargspec(condition_fn).args
unfilled_args = len(args_spec) - (1 if is_bound else 0)
else:
if not isfunction(condition_fn):
condition_fn = condition_fn.__call__
args_spec = getfullargspec(condition_fn).args
unfilled_args = len(args_spec)
condition = \
condition_fn if unfilled_args else lambda driver: condition_fn()
wait = WebDriverWait(
self.require_driver().unwrap(), timeout_secs,
poll_frequency=interval_secs
)
wait.until(condition)
示例2: loadmap
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def loadmap(self):
'''
loadmap()
Creates a browser object and loads the webpage.
It sets up the map to the proper zoom level.
Returns the browser on success, None on fail.
'''
browser = webdriver.PhantomJS(desired_capabilities={'phantomjs.page.settings.resourceTimeout': '20000'})
browser.set_window_size(abovetustin_image_width, abovetustin_image_height)
print("getting web page {}".format(self.url))
browser.set_page_load_timeout(15)
browser.get(self.url)
# Need to wait for the page to load
timeout = g_request_timeout
print ("waiting for page to load...")
wait = WebDriverWait(browser, timeout)
element = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'vrsMenu')))
self.browser = browser
示例3: __init__
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def __init__(self, cookies_list):
self.headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.86 Safari/537.36',
}
option = ChromeOptions()
option.add_experimental_option('excludeSwitches', ['enable-automation'])
option.add_experimental_option("prefs", {"profile.managed_default_content_settings.images": 2}) # 不加载图片,加快访问速度
option.add_argument('--headless')
self.driver = webdriver.Chrome(options=option)
self.driver.get('https://i.taobao.com/my_taobao.htm')
for i in cookies_list:
self.driver.add_cookie(cookie_dict=i)
self.driver.get('https://i.taobao.com/my_taobao.htm')
self.wait = WebDriverWait(self.driver, 10) # 超时时长为10s
# 模拟向下滑动浏览
示例4: get_latest_wallpapers
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_latest_wallpapers():
browser = webdriver.PhantomJS(PHANTOMJS_PATH, service_args=['--ignore-ssl-errors=true', '--ssl-protocol=any'])
today_date = time.strftime("%d+%b+%Y")
yesterday = datetime.now() - timedelta(days=1)
yesterday_date = yesterday.strftime('%d+%b+%Y')
first_page_url = 'http://www.espncricinfo.com/ci/content/image/?datefrom='+yesterday_date+'&dateupto='+today_date+';'
browser.get(first_page_url)
wait = WebDriverWait(browser, 10)
wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "img-wrap")))
time.sleep(2)
# let's parse our html
soup = BeautifulSoup(browser.page_source, "html.parser")
images = soup.find_all('div', class_='picture')
for image in images:
url = "http://www.espncricinfo.com/" + image.find('a').get('href')
print(url)
示例5: enter_concert
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def enter_concert(self):
self.login()
try:
if self.type == 1: # detail.damai.cn
locator = (By.XPATH, "/html/body/div[1]/div/div[3]/div[1]/a[2]/div")
elif self.type == 2: # piao.damai.cn
locator = (By.XPATH, "/html/body/div[1]/div/ul/li[2]/div/label/a[2]")
WebDriverWait(self.driver, self.total_wait_time, self.refresh_wait_time).until(
EC.text_to_be_present_in_element(locator, self.nick_name))
self.status = 1
print("###登录成功###")
except Exception as e:
print(e)
self.status = 0
self.driver.quit()
raise Exception("***错误:登录失败,请检查配置文件昵称或删除cookie.pkl后重试***")
示例6: _init_browser
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _init_browser(self, browser, url_path=""):
"""
Open browser with LEGO shop URL (index page if path not set)
"""
self.shop_url = "https://www.lego.com/%s" % url_path
self._load_driver(browser)
# Selenium can't find some elements otherwise
self.browser.maximize_window()
self.browser.get(self.shop_url)
# will wait to 5 sec for and ExpectedCondition success,
# otherwise exception TimeoutException
self.wait = WebDriverWait(self.browser, 5)
self.browser_info()
示例7: get_selenium_js_html
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_selenium_js_html(url):
# browser = webdriver.PhantomJS(executable_path=r'D:\Python2.7\Scripts\phantomjs.exe')
options = Options()
options.add_argument('-headless') # 无头参数
driver = Chrome(executable_path='chromedriver', chrome_options=options)
wait = WebDriverWait(driver, timeout=10)
driver.get(url)
time.sleep(3)
# 执行js得到整个页面内容
html = driver.execute_script("return document.documentElement.outerHTML")
driver.close()
return html
# 获取公众号文章内容
示例8: get_score
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def get_score(self):
login_url = r'https://pc.xuexi.cn/points/login.html.*' # check if it has been login
# score_url = r'https://pc.xuexi.cn/points/my-points.html.*'
# if not re.match(login_url, self.driver.current_url) and not re.match(score_url, self.driver.current_url):
# self.driver.get('https://pc.xuexi.cn/points/my-points.html')
# self.driver.switch_to.default_content()
score_url = 'https://pc.xuexi.cn/points/my-points.html'
try:
self.driver.get(score_url)
except selenium.common.exceptions.NoSuchWindowException as error:
raise Exception(error)
if re.match(login_url, self.driver.current_url):
if not self.login():
return []
else:
try:
WebDriverWait(self.driver, 3).until(
expected_conditions.presence_of_element_located((By.XPATH, '//div[@class="my-points-card-text"]')))
except Exception:
return []
score = []
app.log(u'当前得分情况:')
score_title = iter([u'每日登陆', u'阅读文章', u'观看视频', u'文章学习时长', u'视频学习时长'])
for s in self.driver.find_elements_by_xpath('//div[@class="my-points-card-text"]'):
app.log(u'%s: %s' % (next(score_title), s.text), printtime=False)
try:
score.append({'score': int(s.text.split('/')[0][:-1]), 'target': int(s.text.split('/')[1][:-1])})
except Exception:
pass
return score
示例9: wait_until_element_is_invisible_by_locator
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_element_is_invisible_by_locator(context, locator_tuple,
timeout=TIMEOUT_IN_S):
wait = WebDriverWait(context.browser, timeout)
wait.until(EC.invisibility_of_element_located(locator_tuple))
示例10: _wait_until_elements_are_visible_by_locator
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _wait_until_elements_are_visible_by_locator(context, locator_tuple,
timeout=TIMEOUT_IN_S):
wait = WebDriverWait(context.browser, timeout)
wait.until(EC.presence_of_all_elements_located(locator_tuple))
return context.browser.find_elements(locator_tuple[0], locator_tuple[1])
示例11: _wait_until_element_is_visible_by_locator
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def _wait_until_element_is_visible_by_locator(context, locator_tuple,
timeout=TIMEOUT_IN_S):
wait = WebDriverWait(context.browser, timeout)
wait.until(EC.visibility_of_element_located(locator_tuple))
return context.browser.find_element(locator_tuple[0], locator_tuple[1])
示例12: wait_for_condition
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_for_condition(context, predicate_func, timeout=TIMEOUT_IN_S,
poll_frequency=0.1):
wait = WebDriverWait(context.browser, timeout,
poll_frequency=poll_frequency)
wait.until(predicate_func)
示例13: wait_until_button_is_visible
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def wait_until_button_is_visible(context, title, timeout=TIMEOUT_IN_S):
wait = WebDriverWait(context.browser, timeout)
locator_tuple = (By.XPATH, ("//%s[contains(.,'%s')]" % ('button', title)))
wait.until(EC.visibility_of_element_located(locator_tuple))
示例14: login
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def login(self):
"""登陆模块"""
self.driver.get('https://passport.damai.cn/login')
# WebDriverWait(self.driver, 10).until(
# EC.presence_of_element_located((By.ID, 'alibaba-login-box')))
# self.driver.switch_to.frame('alibaba-login-box')
# self.driver.find_element_by_xpath('//*[@id="fm-login-id"]').send_keys(self.phone_num)
# self.driver.find_element_by_xpath('//*[@id="fm-login-password"]').send_keys(self.passwd)
WebDriverWait(self.driver, 3000).until(
EC.presence_of_element_located((By.XPATH, '//a[@data-spm="duserinfo"]/div')))
print('登陆成功')
user_name = self.driver.find_element_by_xpath('//a[@data-spm="duserinfo"]/div').text
print('账号:', user_name)
示例15: detail_page_auto
# 需要导入模块: from selenium.webdriver.support import wait [as 别名]
# 或者: from selenium.webdriver.support.wait import WebDriverWait [as 别名]
def detail_page_auto(self):
"""详情页自动"""
self.driver.get('https://detail.damai.cn/item.htm?id=593089517773')
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//button[@data-spm="dconfirm"]')))
dconfirm_button = self.driver.find_element_by_xpath('//button[@data-spm="dconfirm"]')
while dconfirm_button.get_attribute('class') == 'privilege_sub disabled':
print(dconfirm_button.get_attribute('class'), '确定按钮无法点击,刷新页面')
self.driver.refresh()
WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.XPATH, '//button[@data-spm="dconfirm"]')))
try:
dconfirm_button = self.driver.find_element_by_xpath('//button[@data-spm="dconfirm"]')
except Exception as e:
print('寻找按钮失败', e)
self.driver.find_element_by_css_selector("#privilege_val").send_keys(self.dotakey)
dconfirm_button.click()
if self.quantity != 1:
try:
self.driver.find_element_by_xpath(
'//a[@class="cafe-c-input-number-handler cafe-c-input-number-handler-up"]').click()
except Exception as e:
print("未成功点击+号", e)
self.driver.find_element_by_xpath(f'//div[@class="select_right_list"]/div[{self.round}]/span[2]').click()
dbuy_button = self.driver.find_element_by_xpath('//div[@data-spm="dbuy"]')
print('寻找按钮:', dbuy_button.text)
dbuy_button.click()