2-8 如何使用Expected_conditions判断元素是否可见

from selenium import webdriverimport time#导入expected_conditions预期包判断标题是否正确:from selenium.webdriver.support import expected_conditions as EC#导入WebDriverWaitfrom selenium.webdriver.support.wait import WebDriverWait#导入by:from selenium.webdriver.common.by import Bydriver = webdriver.Chrome()driver.maximize_window()driver.get("http://www.5itest.cn/register")# EC.title_is #title_is代表现在的title和预期的title是一样的time.sleep(5)print(EC.title_contains("注册"))   #title_contains代表只要包含就可以了# element = driver.find_element_by_class_name("controls")#拿到By定位的元素:locator = (By.CLASS_NAME,"controls")#visibility_of_element_located使用可见度/是否可见:# EC.visibility_of_element_located(element)#使用WebDriverWait的until寻找父级元素:WebDriverWait(driver,1).until(EC.visibility_of_element_located(locator))#关闭driver可以有效避免电脑和浏览器卡顿:driver.close()#presence_of_element_located元素的存在位置:EC.presence_of_element_located()#使用id进行定位邮箱地址:# driver.find_element_by_id("register_email").send_keys("")#使用class定位用户名、find_elements_by_class_name返回的是列表、列表才可以len、先定义父类、再定义子类:# user_name_element_node = driver.find_elements_by_class_name("controls")[1]# user_element = user_name_element_node.find_element_by_class_name("form-control")# user_element.send_keys("dsads")#使用name定位密码:# driver.find_element_by_name("password").send_keys("990496256dd")#使用xpath定位验证码:# driver.find_element_by_xpath(‘//*[@id="captcha_code"]‘).send_keys("111111")

相关推荐