关闭页面展示,运行selenium
#关闭浏览器展示模式 判断元素是否存在 # 导包 from selenium import webdriver from selenium.webdriver.common.by import By from time import sleep from selenium.webdriver.chrome.options import Options # 定义类 class GetEle: def __init__(self,driver): self.driver=driver def get_e(self,loc): e=driver.find_element(By.CSS_SELECTOR,loc) print(e.text) def is_find(self,loc): flag=driver.find_element(By.CSS_SELECTOR,loc).is_displayed() print(fr"存在吗?:{flag}") def is_selec(self,loc): driver.find_element(By.CSS_SELECTOR,loc).click() sleep(3) flag=driver.find_element(By.CSS_SELECTOR,loc).is_selected() print(fr"被选中l吗?:{flag}") def is_en(self,loc): flag=driver.find_element(By.CSS_SELECTOR,loc).is_enabled() print(fr"启用状态码?:{flag}") # 调用 if __name__ == '__main__': # 创建无头浏览器选项 options = Options() options.add_argument("--headless") # 调用driver driver=webdriver.Chrome(options=options) # url url=r"XXXmyself\1.html" driver.get(url) # 实例化类 web_e=GetEle(driver) # 调用方法4 loc4='[type="button"]' web_e.is_en(loc4) # 退出 driver.quit()