Selenium中expected_conditions的等待条件

等待条件如下:

1.PNG

实例

创建一个html文件,内容如下




    
    Title



创建一个py文件,内容如下

from selenium import webdriver
from time import sleep
import os

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


class TestCase(object):
    def __init__(self):
        self.driver = webdriver.Chrome()
        path = os.path.dirname(os.path.abspath(__file__))  # os.path.abspath当前文件路径
        file_path = 'file:///' + path + '/test_wait.html'
        self.driver.get(file_path)

    def test(self):
        self.driver.find_element_by_id('btn').click()
        wait = WebDriverWait(self.driver,3)
        wait.until(EC.text_to_be_present_in_element((By.ID,'id2'),'id 2'))
        print(self.driver.find_element_by_id('id2').text)
        print('ok')

if __name__ == '__main__':
    case = TestCase()
    case.test()

你可能感兴趣的:(Selenium中expected_conditions的等待条件)