当前位置:网站首页>Selenium displays webdriverwait

Selenium displays webdriverwait

2022-04-23 20:43:00 weixin_ fifty-two million five hundred and thirty-nine thousand

Routine usage

from selenium.webdriver.common.by import By
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import  expected_conditions as EC


class HomePage:
    exists_link = (By.XPATH, '/html/body/div[2]/div/div[2]/div[1]/span')

    def __init__(self, driver: WebDriver):
        self.driver = driver

    def get_element_exists(self):
        try:
            WebDriverWait(self.driver, 10).until(EC.visibility_of_element_located(self.exists_link))
        except:
            return False
        else:
            return True

2、 Waiting conditions and their meaning

Waiting conditions meaning
title_is
The title is something
title_contains
The title contains something
presence_of_element_located
Node load out , Incoming location tuples , Such as (By.ID, 'p')
visibility_of_element_located
Nodes are visible , Incoming location tuples
visibility_of
so , Pass in the node object
presence_of_all_elements_located
All nodes are loaded out
text_to_be_present_in_element
A node text contains a text
text_to_be_present_in_element_value
A node value contains a text
frame_to_be_available_and_switch_to_it frame
Load and switch
invisibility_of_element_located
Nodes are not visible
element_to_be_clickable
Node clickable
staleness_of
Determine whether a node is still DOM, Can determine whether the page has been refreshed
element_to_be_selected
Nodes can be selected , Pass node object
element_located_to_be_selected
Nodes can be selected , Incoming location tuples
element_selection_state_to_be
Pass in the node object and status , Equal return True, Otherwise return to False
element_located_selection_state_to_be
Incoming location tuples and status , Equal return True, Otherwise return to False
alert_is_present
Does it appear? Alert

版权声明
本文为[weixin_ fifty-two million five hundred and thirty-nine thousand]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204232042544815.html