webdirver

01.访问某个网站
def get(self,url):
    self.driver.get(url)
02.网页的前进和后退
def forward(self):
    self.driver.forward()

def back(self):
    self.driver.back()
03.刷新当前网页
def refresh(self):
    self.driver.refresh()
04.浏览器窗口最大化
def maximize_window(self):
    self.driver.maximize_window()
05.获取并设置当前窗口的位置
def get_window_position(self):
    return self.driver.get_window_position()
06.获取并设置当前窗口的大小
def get_window_rect(self):
    return self.get_window_rect()
07.获取页面的Title属性值
def title(self):
    return self.driver.title
08.获取页面HTML源代码
def page_source(self):
    return self.driver.page_source
09.获取当前页面的URL地址
def current_url(self):
    return self.driver.current_url
10.获取与切换浏览器窗口句柄
# 用于切换window 窗口用的, 通过页面标题 或者 页面相关信息文
def switch_window(self, page_keywords):
    # window_name: The name or window handle of the window to switch to
    for x in self.driver.window_handles:
        self.driver.switch_to.window(x)
        if page_keywords in self.driver.page_source.encode("utf-8"):
            print(self.driver.title)
            print(">>>Switch window is successful<<<")
            break
        else:
            print("not find the windows....."+page_keywords[0])

11.获取页面元素的基本信息
# 获取标签名
def tag_name(self,locator_type, locator_value):
    return self.find_element(locator_type, locator_value).tag_name()
#获取元素大小
def size(self,locator_type, locator_value):
    return self.find_element(locator_type, locator_value).size()
#获取元素的ID
def id(self, locator_type, locator_value):
    return self.find_element(locator_type, locator_value).id()
#获取元素的位置信息
def location(self, locator_type, locator_value):
    return self.find_element(locator_type, locator_value).location()
#获取屏幕左上角的位置
def location_once_scrolled_into_view(self, locator_type, locator_value):
    return self.find_element(locator_type, locator_value).location_once_scrolled_into_view()
#获取当前元素的父元素
def parent(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).parent()
#一个包含元素大小和位置的字典
def rect(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).rect()
#获取当前元素的屏幕截图作为二进制数据。
def screenshot_as_png(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).screenshot_as_png()
# 获取当前元素的屏幕截图,作为base64编码的字符串
def screenshot_as_base64(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).screenshot_as_base64()
#获取当前元素的截图,给定名称
def screenshot(self, locator_type, locator_value, filename):
    return self.driver.find_element(locator_type, locator_value).screenshot(filename)
12.获取页面元素的文本信息
def text(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).text()
13.判断页面元素是否可见
def is_displayed(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).is_displayed()
14.判断页面元素是否可操作
def is_enabled(self, locator_type, locator_value):
    return self.driver.find_element(locator_type, locator_value).is_enabled()

def is_selected(self,locator_type, locator_value):
    self.find_element(locator_type, locator_value).is_selected()
15.获取页面元素的属性
def get_attribute(self, locator_type, locator_value, attribute_name):
    self.find_element(locator_type, locator_value).get_attribute(attribute_name)
16.获取页面元素的CSS属性值
def value_of_css_property(self, locator_type, locator_value, property_name):
      self.find_element(locator_type, locator_value).value_of_css_property(property_name)
17.清空输入框中的内容
def clear(self, locator_type, locator_value):
       self.find_element(locator_type, locator_value).clear()
18.在输入框中输入指定内容
def send_keys(self,locator_type, locator_value, input_value):
    self.find_element(locator_type, locator_value).send_keys(input_value)
19.单击按钮
def click(self,locator_type, locator_value):
    self.find_element(locator_type, locator_value).click()
20.双击某个元素
def double_click(self,locator_type, locator_value):
    action_chains = ActionChains(self.driver)
    action_chains.double_click(self.find_element(locator_type, locator_value)).perform()
21.操作单选下拉列表
def select_by_index(self,locator_type, locator_expression,operate_value):
    select = Select(self.find_element(locator_type,locator_expression))
    select.select_by_index(operate_value)

def select_by_visible_text(self,locator_type, locator_expression, operate_value):
    select = Select(self.find_element(locator_type, locator_expression))
    select.select_by_visible_text(operate_value)

def select_by_value(self,locator_type, locator_expression, operate_value):
    select = Select(self.find_element(locator_type, locator_expression))
    select.select_by_value(operate_value)
22.断言单选列表选项值
 
23.操作多选的选择列表

24.操作可以输入的下拉列表

25.操作单选框

26.操作复选框
27.断言页面源码中的关键字
28.对当前浏览器窗口截屏
    def get_screenshot_as_file(self,filename):
            result =self.driver.get_screenshot_as_file(filename)
29.拖拽页面元素
30.模拟键盘单个按键操作
31.模拟组合按键操作
32.模拟鼠标右键
33.模拟鼠标左键按下与释放
34.保持鼠标悬停在某个元素上
35.判断页面元素是否存在
36.隐式等待
37.显式等待
38.显式等待中期望的场景
39.使用Title属性识别和操作新弹出的浏览器窗口
40.通过页面的关键内容识别和操作新浏览器窗口
41.操作Frame中的页面元素
42.使用Frame中的HTML源码内容操作Frame
43.操作IFrame中的页面元素
44.操作JavaScript的Alert弹窗
45.操作JavaScript的confirm弹窗
46.操作JavaScript的prompt弹窗
47.操作浏览器的Cookie
def get_cookies(self):
    self.driver.get_cookies()

def set_cookie(self, cookie_dict):
    self.driver.add_cookie(cookie_dict)

def delete_all_cookies(self):
    self.driver.delete_all_cookies()

def delete_cookie(self, name):
    self.driver.delete_cookie(name)
48.指定页面加载时间
def set_page_load_timeout(self, time_to_wait):
    self.driver.set_page_load_timeout(time_to_wait)

你可能感兴趣的:(webdirver)