from selenium import webdriver class keyWordDriven(object): def __init__(self,browser_type,url): self.driver=self.open_browser(browser_type) self.driver.get(url) def open_browser(self,browser_name): if browser_name == 'Edge': driver = webdriver.Edge() print("Edge browser success open") elif browser_name == 'Chrome': driver = webdriver.Chrome() print("Chrome browser success open") elif browser_name == 'Firefox': driver = webdriver.Firefox() print("Firefox browser success open") elif browser_name == 'Ie': driver = webdriver.Ie() print("Ie browser success open") elif browser_name == 'Opera': driver = webdriver.Opera() print("Opera browser success open") else: print("browser name error") return driver driver.implicitly_wait(5) driver.maximize_window() def close_browser(self): self.driver.quit() def locator(self,locator_type,locator): if locator_type=='id': el=self.driver.find_element_by_id(locator) return el elif locator_type=='xpath': el=self.driver.find_element_by_xpath(locator) return el elif locator_type=='name': el=self.driver.find_element_by_name(locator) return el elif locator_type=='class': el=self.driver.find_element_by_class_name(locator) return el elif locator_type=='tag': el=self.driver.find_element_by_tag_name(locator) return el elif locator_type=='link': el=self.driver.find_element_by_link_text(locator) return el elif locator_type=='css': el=self.driver.find_element_by_css_selector(locator) return el elif locator_type=='partial_link': el=self.driver.find_element_by_partial_link_text(locator) return el def input_text(self,locator_type,locator,text): self.locator(locator_type,locator).send_keys(text) def click_element(self,locator_type,locator): self.locator(locator_type,locator).click() def clear_text(self,locator_type,locator): self.locator(locator_type, locator).clear() if __name__ == '__main__': tk1=keyWordDriven('Edge','https://www.baidu.com') tk1.input_text('id','kw','selenium') tk1.click_element('id','su')
selenium关键字驱动
最新推荐文章于 2024-03-13 20:58:36 发布