本文整理匯總了Python中selenium.webdriver.support.expected_conditions.visibility_of方法的典型用法代碼示例。如果您正苦於以下問題:Python expected_conditions.visibility_of方法的具體用法?Python expected_conditions.visibility_of怎麽用?Python expected_conditions.visibility_of使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類selenium.webdriver.support.expected_conditions
的用法示例。
在下文中一共展示了expected_conditions.visibility_of方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wait_until_visibilty_is_confirmed
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import visibility_of [as 別名]
def wait_until_visibilty_is_confirmed(self, browser_instance,
element, timeout=5):
try:
WebDriverWait(browser_instance, int(timeout)).until(EC.visibility_of(element))
status = True
except TimeoutException:
print_error("Element not visible after {0} seconds".format(timeout))
status = False
except Exception as e:
print_error("An Exception Ocurred: {0}".format(e))
status = "ERROR"
return status
示例2: get_employees
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import visibility_of [as 別名]
def get_employees(self, wait_time=10):
list_css = "search-results"
next_xpath = '//button[@aria-label="Next"]'
driver = self.driver
see_all_employees = driver.find_element_by_xpath('//a[@data-control-name="topcard_see_all_employees"]')
driver.get(see_all_employees.get_attribute("href"))
_ = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CLASS_NAME, list_css)))
total = []
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight/2));")
time.sleep(1)
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight*3/4));")
results_list = driver.find_element_by_class_name(list_css)
results_li = results_list.find_elements_by_tag_name("li")
for res in results_li:
total.append(self.__parse_employee__(res))
while self.__find_enabled_element_by_xpath__(next_xpath):
driver.find_element_by_xpath(next_xpath).click()
_ = WebDriverWait(driver, wait_time).until(EC.presence_of_element_located((By.CLASS_NAME, list_css)))
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight/4));")
time.sleep(1)
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight/3));")
time.sleep(1)
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight/2));")
time.sleep(1)
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight*2/3));")
time.sleep(1)
driver.execute_script("window.scrollTo(0, Math.ceil(document.body.scrollHeight*3/4));")
results_list = driver.find_element_by_class_name(list_css)
results_li = results_list.find_elements_by_tag_name("li")
for res in results_li:
_ = WebDriverWait(driver, wait_time).until(EC.visibility_of(res))
total.append(self.__parse_employee__(res))
return total
示例3: wait_displayed
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import visibility_of [as 別名]
def wait_displayed(self, timeout=30):
"""Wait for element to be displayed
:Returns:
The element
"""
wait = WebDriverWait(self.parent, timeout)
message = ('Timeout waiting for element {} to be displayed'
.format(self.name))
wait.until(ec.visibility_of(self), message=message)
return self
示例4: wait_not_displayed
# 需要導入模塊: from selenium.webdriver.support import expected_conditions [as 別名]
# 或者: from selenium.webdriver.support.expected_conditions import visibility_of [as 別名]
def wait_not_displayed(self, timeout=30):
"""Wait for element to be not displayed
:Returns:
The element
"""
wait = WebDriverWait(self.parent, timeout)
message = ('Timeout waiting for element {} to be not displayed'
.format(self.name))
wait.until_not(ec.visibility_of(self), message=message)
return self