def __init__(self, p_scenario): Scenario.__init__(self, p_scenario=p_scenario) if self.getAutomation(): print("this scene need automation driver!") self._driver = Configure.get_chrome_webdriver() else: self._driver = Configure.get_http_lowlevel_webdriver()
def do(self, p_location=None): driver = Configure.get_chrome_webdriver() if self._script: if not self._async: driver.execute_script(script=self._script) else: driver.execute_async_script(script=self._script)
def find(p_id, p_class, p_xpath, p_name, p_tag): driver = Configure.get_chrome_webdriver() if p_xpath: return driver.find_elements_by_xpath(p_xpath) xpath = "//" express = "" if p_tag: xpath += p_tag else: xpath += "*" if p_id: express += "contains(@id, '" + p_id + "')" if p_name: if len(express) > 0: express += " and " express += "contains(@name, '" + p_name + "')" if p_class: if len(express) > 0: express += " and " express += "contains(@class, '" + p_class + "')" if len(express) > 0: express = "[" + express + "]" xpath += express return driver.find_elements_by_xpath(xpath) '''
def switch_frame(self): driver = Configure.get_chrome_webdriver() xpath = None if self._frame_index: xpath = "//iframe[" + str(self._frame_index) + "]" frame = Locator.find(self._frame_id, self._frame_class, xpath, self._frame_name) driver.switch_to.frame(frame) print(driver.page_source)
def switch_window(self): driver = Configure.get_chrome_webdriver() handles = driver.window_handles print("switch window: " + self._window) if self._window: driver.switch_to.window(self._window) driver.implicitly_wait(30) driver.set_window_size(1920, 1080) return print("switch url: " + self._url) if self._url: for handle in handles: print("switch to window: " + handle) driver.switch_to.window(handle) driver.implicitly_wait(30) driver.set_window_size(1920, 1080) cur_url = driver.current_url print("window url: " + cur_url) if cur_url.find(self._url) >= 0: break
def capture_whole(self, p_file=None, p_url=None): #get_phantomjs_webdriver().get(p_url) os.chdir(Configure.get_ouput_dir()) file_path = Configure.get_ouput_dir()+"/snapshot" if not os.path.exists(file_path): os.mkdir("snapshot") if p_file == None: p_file = "snapshot_"+str(uuid.uuid1())+".png" print (file_path+"/"+p_file) print (Configure.get_chrome_webdriver().get_window_size()) #Get web page's actual height clientHeight = Configure.get_chrome_webdriver().execute_script("return document.body.clientHeight;") print (clientHeight) #Adjuest window's height to fit web page's height cursize = Configure.get_chrome_webdriver().get_window_size() Configure.get_chrome_webdriver().set_window_size(cursize["width"], clientHeight) stored = Configure.get_chrome_webdriver().get_screenshot_as_file(file_path+"/"+p_file) return stored
def findPagination(self): driver = Configure.get_chrome_webdriver() selector = Selector(text=driver.page_sources)
def find_elements_with_class(p_class): if p_class == None: return None driver = Configure.get_chrome_webdriver() return driver.find_elements_by_class_name(p_class)
def find_elements_with_tagname(p_tag): if p_tag == None: return None driver = Configure.get_chrome_webdriver() return driver.find_elements_by_tag_name(p_tag)
def find_elements_with_xpath(p_xpath): if p_xpath == None: return None driver = Configure.get_chrome_webdriver() return driver.find_elements_by_xpath(p_xpath)
def find_elements_with_id(p_id): if p_id == None: return None driver = Configure.get_chrome_webdriver() return driver.find_elements_by_id(p_id)
def __init__(self, p_scenario): Scenario.__init__(self, p_scenario=p_scenario) self._driver = Configure.get_chrome_webdriver()
def switch_parent_frame(self): Configure.get_chrome_webdriver().switch_to.parent_frame()
def input(self, p_value): func = u"select('"+p_value+"',"+self._name+","+self._tag+","+self._class+","+self._id+");" print (func) Configure.get_chrome_webdriver().execute_script(self._find_scripts.decode("utf-8")+" "+self._select_scripts.decode("utf-8")+" "+func);