예제 #1
0
 def click(self, xpath, css="xpath"):
     """
     1.点击一个元素
     2.例子:driver.click(".//*[@id='su']")
     """
     try:
         self.get_element(xpath, css).click()
     except:
         log_exception_exit('无法点击元素:' + xpath)
예제 #2
0
 def open(self, url='http://mis.1mifudao.com/'):
     """
     1.打开一个网址
     2.例子: driver.open("https://www.baidu.com")
     """
     try:
         self.driver.get(url)
     except BaseException:
         log_exception_exit('打开url错误')
     time.sleep(0.5)
예제 #3
0
 def __init__(self, browser='chrome'):
     try:
         if browser.upper() == 'CHROME':
             driver = webdriver.Chrome()
             driver.implicitly_wait(5)  # 隐式等待
         else:
             driver = False
         self.driver = driver
         self.url = driver.current_url
         self.driver.maximize_window()
         logger.info('打开浏览器成功')
     except:
         log_exception_exit('打开浏览器错误')
예제 #4
0
 def get_elements(self, xpath, css="xpath"):
     try:
         self.element_wait(xpath)
         if css == "xpath":
             element = self.driver.find_elements_by_xpath(xpath)
         elif css == "id":
             element = self.driver.find_elements_by_id(xpath)
         elif css == "selector":
             element = self.driver.find_elements_by_css_selector(xpath)
         else:
             element = self.driver.find_elements_by_partial_link_text(xpath)
         return element
     except BaseException:
         log_exception_exit('定位不到元素:' + xpath)
예제 #5
0
 def alert(self, common="text"):
     """
     1、获得当前弹窗信息或者操作
     :param common: text-获得弹窗文本,accept-点击确定按钮,dismiss-点击取消按钮
     :return:
     """
     try:
         al = Alert(self.driver)
     except:
         time.sleep(0.5)
         al = Alert(self.driver)
     try:
         if common == "text":
             return al.text
         elif common == "accept":
             Alert(self.driver).accept()
         elif common == 'dismiss':
             Alert(self.driver).dismiss()
         else:
             pass
     except BaseException:
         log_exception_exit('没有找到弹窗')