class LoginPage(object): username_locator = By.ID("username") password_locator = By.ID("passwd") login_button_locator = By.ID("login") def __init__(self): self.driver = webdriver.Firefox(executable_path="H:\\Webdrivers\\geckodriver.exe")
def select_return_date_for_journey(self, pick_up_date): try: pick_up_date = pick_up_date.strptime("%d %B %Y") return_date = (pick_up_date + datetime.timedelta(days=7)).strftime("%d %B %Y") date = pick_up_date.split(" ")[0] month = pick_up_date.split(" ")[1] year = pick_up_date.split(" ")[2] month_year = month + year WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located(By.XPATH(INPUT_DATE))) self.driver.find_element_by_xpath(INPUT_DATE).click() WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located( By.XPATH(WEBELEMENt_INPUT_CALENDER_WIDGET))) self.driver.find_element_by_xpath( WEBELEMENT_MONTH_DROPDOWN.format(month_year)).click() calendar_rows = self.driver.find_elements_by_xpath( WEBELEMET_CALENDAR_ROWS) for row in calendar_rows: calendar_columns = self.driver.find_elements_by_xpath( row.find_elements_by_xpath("./td/a")) for col in calendar_columns: col_value = col.text if col_value == date: col.click() return return_date except Exception as err: logging.error("issue in clicking return date")
def config_bt_bot(driver, webdriver, chunk, bot): h = MadHatterBot() sleep(1) chunk.reset_index(drop=True, inplace=True) clones = [] for ii in range(len(chunk)): name = F"{bot.priceMarket.primaryCurrency}|{bot.priceMarket.secondaryCurrency},#{ii}" clone = h.clone_bot_for_bt2(bot, str(name)) print(clone.name, 'Clonr NAME') config = h.apply_config_to_madhatter_bot(clone, chunk, ii) clones.append(clone) element = WebDriverWait(driver, 120).until( EC.presence_of_element_located(driver, By.XPATH("//*[@data-guid=]"))) try: driver.find_element_by_id("botRemoteStartCustom").click() except: driver.find_element_by_id("botRemoteWindow").click() finally: driver.find_element_by_id("botRemoteStartCustom").click() try: driver.find_element_by_link_text('Close').click() except: pass bt_over = f"The backtest of bot {name} has finished" element = WebDriverWait(driver, 120).until( EC.text_to_be_present_in_element((By.XPATH("//", bt_over)))) chunk['roi'][ii] = h.return_bot(clone.guid).roi h.delete_temp_bot(clone) return chunk
def selct_pick_up_date_fpr_journey(self): """ Method to select pickupdate from budget page :param date: :return: """ try: WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located(By.XPATH(INPUT_DATE))) self.driver.find_element_by_xpath(INPUT_DATE).click() WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located( By.XPATH(WEBELEMENt_INPUT_CALENDER_WIDGET))) current_date = datetime.date.today() pick_up_date = (current_date + datetime.timedelta(days=7)).strftime("%d %B %Y") date = pick_up_date.split(" ")[0] month = pick_up_date.split(" ")[1] year = pick_up_date.split(" ")[2] month_year = month + year self.driver.find_element_by_xpath( WEBELEMENT_MONTH_DROPDOWN.format(month_year)).click() calendar_rows = self.driver.find_elements_by_xpath( WEBELEMET_CALENDAR_ROWS) for row in calendar_rows: calendar_columns = self.driver.find_elements_by_xpath( row.find_elements_by_xpath("./td/a")) for col in calendar_columns: col_value = col.text if col_value == date: col.click() return pick_up_date except Exception as err: logging.error("Issue in selecting pickup date")
def test_javascriptexecuter(self): ss_path = alist[4] driver = self.driver self.driver.get(alist[0]) searchtext=driver.find_element(By.id("twotabsearchtextbox")) searchtext.send_keys("Mobiles") gobutton= driver.find_element(By.CSS_SELECTOR("input[value=Go]")) safeJavaScriptclick(gobutton)
def clickNextPage(self): print("clickNextPage zzzz") disclaimerBanners = self.driver.find_elements( By.CLASS_NAME("flaticon-cross")) if (len(disclaimerBanners) != 0): disclaimerBanners[0].click() buttons = self.driver.find_element( By.CLASS_NAME("lli-grid-pager__link--next")) if (not ("disabled" in buttons.get_attribute("class"))): buttons.click()
class Search: def __init__(self, driver): self.driver = driver searchbar = By.ID("search_query_top") searchbar.send_keys("printed") searchbar.send_keys(Keys.ENTER) print( By.XPATH( "//*[@id='center_column']/h1/span[@class='heading-counter']").text)
def get_col_text(self, by, loc, row, col): '''传入table定位,by,loc 获取table中row行,col列的文本 ''' table_ele = self.find_element(by, loc) try: rows = table_ele.find_elements(By.TAG_NAME("tr")) cols = rows(row).find_elements(By.TAG_NAME("td")) return cols(col).text except: return None self.log.info("【获取元素文本】: 定位方式:{} , 定位表达式:{}".format(by, loc)) return self.find_element(by, loc).text
def _get_booking_status(self, weekday_index, time_index): xpath = self._get_xpath_from_datetime(weekday_index, time_index) status_text = None if self.driver.find_elements(By.XPATH(xpath + '/a')).__sizeof__() != 0: status = self._wait_and_select_element_by_xpath(xpath + '/a') elif self.driver.find_elements(By.XPATH(xpath + '/span')).__sizeof__() != 0: status = self._wait_and_select_element_by_xpath(xpath + '/span') if status: status_text = status.text return status_text
def bleConnect_long(self): #进入设备详情页 self.enter_device() try: WebDriverWait( self.driver, 60).until(lambda x: x.find_element_by_android_uiautomator( 'new UiSelector().text(\"已连接\")')).is_displayed() except: print('蓝牙首次未连接') self.loger.info('蓝牙首次未连接') else: print('蓝牙首次连接') self.loger.info('蓝牙首次连接') # 进入设置页 btn_settting = self.driver.find_element_by_id("btn_setting") sleep(1) btn_settting.click() sleep(3) while True: try: WebDriverWait(self.driver, 10, 0.5).until( (By.ID('device_lock_switch'))).is_clickable() except: print('蓝牙断开连接') self.loger.info('蓝牙断开连接') self.screenshot('蓝牙断开连接') break else: print('5s检测一次,蓝牙正常连接') self.loger.info('5s检测一次,蓝牙正常连接') sleep(5)
def testSchedule(self): assert self.driver.find_element_by_id('tab_icon').is_displayed() self.driver.swipe(516, 1262, 564, 1310) self.driver.scroll("7, 1233, 713, 1233") self.driver.swipe( "start_x'=516, 'start_y'=1262, 'end_x'=564, 'end_y'=1310, 10") self.driver.find_element_by_id('tab_icon').click() self.driver.find_element_by_xpath( "//androidx.appcompat.app.ActionBar.Tab[@content-desc='SCHEDULE']/android.view.ViewGroup[@bounds='[516,1262][564,1310]']" ) self.driver.find_element_by_xpath( By.XPATH( "//androidx.appcompat.app.ActionBar.Tab[@content-desc='SCHEDULE']/android.view.ViewGroup" )).click() assert self.driver.find_element_by_accessibility_id( 'Open navigation drawer').is_displayed() assert self.driver.find_element_by_id('titleOnToolbar').is_displayed() assert self.driver.find_element_by_id('actionButton').is_displayed() assert self.driver.find_element_by_id('scroll_to_today').is_displayed() assert self.driver.find_element_by_accessibility_id( 'Display Removed Plan').is_displayed() assert self.driver.find_element_by_id('More options').is_displayed() assert self.driver.find_element_by_id( 'downloadImageView').is_displayed() assert self.driver.find_element_by_id('announceText').is_displayed() assert self.driver.find_element_by_id('displayDate').is_displayed() assert self.driver.find_element_by_id('menuButton').is_displayed() assert self.driver.find_element_by_id( 'displayCustomerName').is_displayed() assert self.driver.find_element_by_id('navigationArrow').is_displayed() assert self.driver.find_element_by_id('listView').is_displayed()
class main(): dr = webdriver.Firefox() dr.maximize_window() sleep(5) url = "https://www.imooc.com/user/newlogin" dr.get(url) sleep(3) dr.find_element(By.XPATH('//*[@id="sigin"]/div[1]/h1/span[1]')) sleep(3) dr.find_element(By.NAME("email")).click() sleep(3) dr.find_element(By.NAME("email")).send_keys("*****@*****.**") dr.find_element(By.NAME("password")).send_keys("f12547414") dr.find_element(By.value("登录")).click()
def find_elements(self, by=By.ID, value=None): """ 'Private' method used by the find_elements_by_* methods. :Usage: Use the corresponding find_elements_by_* instead of this. :rtype: list of WebElement """ if not By.is_valid(by) or not isinstance(value, str): raise InvalidSelectorException("Invalid locator values passed in") if self.w3c: if by == By.ID: by = By.CSS_SELECTOR value = '[id="%s"]' % value elif by == By.TAG_NAME: by = By.CSS_SELECTOR elif by == By.CLASS_NAME: by = By.CSS_SELECTOR value = ".%s" % value elif by == By.NAME: by = By.CSS_SELECTOR value = '[name="%s"]' % value return self.execute(Command.FIND_ELEMENTS, {'using': by, 'value': value})['value']
def test_element_to_be_clickable(self): try: WebDriverWait(self.driver, 5).until( EC.element_to_be_clickable( By.XPATH("//button[@title='Subscribe']"))) except TimeoutException: print("Taking more time to load")
def wait_until_visible_by_ID(self, id): try: self._logger.info("----- wait visible by : " + str(id) + " -----") return WebDriverWait(self._driver, 10).until( EC.visibility_of_element_located((By.id(id)))) except WebDriverException as e: self._logger.critical("'Invalid Input : " + str(e))
def GetalertContext(self, driver, Writenotice): # 获取弹框 self.checkelement.Waitelement( driver, 20, By.xpath("//*[@class='alert-container']/div/div")) a = driver.findElement(By.xpath( "//*[@class='alert-container']/div")).getAttribute("class") alerttext = driver.findElement( By.xpath("//*[@class='alert-container']/div/div")).getText() if a.contains("info"): if alerttext.contains(Writenotice): return False logging.info(alerttext) return True else: logging.error(alerttext) return False
def getValue(self, attribute_type=None, idx_or_match=None, element_name=None): element_name = self._get_current_element_name_when_none(element_name) element = self._get_current_element_object_or_search( idx_or_match, element_name) return_value = "" if self.isVisible(idx_or_match, element_name): if attribute_type is None: element_type = self._getElementTagName(element) if "input" in element_type: return_value = element.get_attributes_list( self.AttributeType.VALUE) elif "text" in element_type: return_value = element.text elif "checkbox" in element_type: checkbox_class = element.get_attributes_list( self.AttributeType.CHECKED) if "true" in checkbox_class: return_value = "checked" else: return_value = "unchecked" elif "select" in element_type: for index in range(self.getElementSize(element_name)): select_item = element.find_elements( By.TAG_NAME("option")).get(index) if select_item.is_selected(): return_value = select_item.text elif return_value is None or return_value == "": return_value = element.text else: return_value = element.get_attributes_list(attribute_type) return return_value
def search(keyword, search_url): try: browser.get(search_url) input = wait.until( EC.presence_of_element_located((By.CSS_SELECTOR, '#q'))) submit = wait.until( EC.element_to_be_clickable( (By.CSS_SELECTOR, 'body > div.g-top > div > div > form > input.u-magnifier'))) input.send_keys(keyword) submit.click() time.sleep(1) submit2 = wait.until( EC.element_to_be_clickable(( By.CSS_SELECTOR, 'body > div.search-column1 > div.left-suffix > div > ul.label-block.js-result > li:nth-child(2)' ))) submit2.click() print( EC.findElement( By.cssSelector( "body > div.search-column1 > div.right-content > ul > li:nth-child(1) > a > p" ))) news_num = wait.until( EC.presence_of_element_located(( By.xpath, 'body > div.search-column1 > div.right-content > div > p[2]'))) return news_num.text except TimeoutException: print('搜索超时') return search(keyword, search_url)
def click_logout(self): '''This method clicks on the logout option''' try: WebDriverWait(self.driver, config.driver_wait).until( ec.visibility_of( self.driver.find_element_by_css_selector( self._menu_options))) print('Menu options found') ele_options = self.driver.find_elements_by_css_selector( self._menu_options) for ele in ele_options: print(ele) option = ele.text print(option) if option == 'Log Out': ele.click() break WebDriverWait(self.driver, config.driver_wait).until( ec.presence_of_element_located(By.CSS_SELECTOR(self._log_out))) user_text = self.driver.find_elements_by_xpath(self._log_out) for text in user_text: if text.text == '//logout': print('Logout test passed') else: print('Logout test failed') except Exception as e: print('Menu options not found', e)
class FulfillmentPage: # ELECTRONIC_DELIVERY_TAB PAGE_TITLE = By.TAG_NAME("Electronic delivery") ELECTRONIC_DELIVERY_TAB = By.ID, '__tab_Electronic_delivery' # Tab elements LIST_NAME = By.ID, 'listname' LIST_TYPE = By.ID, 'listtype' # DOWNLOAD_INSURANCE_TAB DOWNLOAD_INSURANCE_TAB = By.ID, '__tab_Download_insurance' # Tab elements # BACKUP_MEDIA_TAB BACKUP_MEDIA_TAB = By.ID, '__tab_Backup_media' # Tab elements # SHIPPING_FEES_TAB SHIPPING_FEES_TAB = By.ID, '__tab_Shipping_fees' SHIPPING_CLASSES = By.ID, 'Shipping classes' DELIVERY_ZONES = By.ID, 'Delivery zones »' SHIPPING_FEE_NAME = By.ID, 'name0' COST_TYPE = By.NAME, 'pricetype0' PRICE_VALUE = By.NAME, 'shipprice0' SHIPPING_TYPE = By.NAME, 'priceapply0' # SHIPPING_CLASSES_PAGE CLASS_NAME = By.ID, 'shipname' PRICE = By.ID, 'shipprice' CURRENCY = By.ID, 'idcurrency_add' TYPE = By.ID, 'pricetype' ADD_BUTTON = By.ID, 'AddShipPrice' BACK_BUTTON = By.LINK_TEXT, 'Back' # DELIVERY ZONES PAGE # Tab elements # SHIPPING_METHODS_TAB SHIPPING_METHODS_TAB = By.ID, '__tab_Shipping_methods' # Tab elements ADD_SHIPPING_METHOD = By.ID, 'shipping_method_name' TRACKING_URL = By.ID, 'tracking_url' ADD_SHIPPING_METHOD_BUTTON = By.ID, 'AddShippingMethod' ACTIVATE_BUTTON = By.ID, 'activate' DEACTIVATE_BUTTON = By.ID, 'deactivate' # PRODUCT_FILES_TAB PRODUCT_FILES_TAB = By.ID, '__tab_Product_files' # Tab elements ADD_NEW_PRODUCT_FILE = By.ID, 'displayname' FILE_VERSION = By.ID, 'fileversion' BROWSE_FILE = By.ID, 'uploadfile' UPLOAD_FILE = By.ID, 'addfile'
def test_user_can_register(self): self.browser.get(self.live_server_url) self.browser.implicitly_wait(1) self.browser.find_element_by_id('register-button').click() username_field = self.browser.find_element_by_id('id_username') username_field.send_keys("testuser123") email_field = self.browser.find_element_by_id('id_email') email_field.send_keys("*****@*****.**") password_field = self.browser.find_element_by_id('id_password') password_field.send_keys("password") self.browser.find_element_by_id('id-register').click() # check for user in db # check is logged in heading = self.browser.find_element_by_tag_name('h1') self.assertEquals(heading.text, 'Search Recipes') # self.browser.find_element_by_id('my-recipes-button').click() # heading = self.browser.find_element_by_tag_name('h1') # self.browser.implicitly_wait(1) # self.assertEquals(heading.text, 'My Recipes') # self.browser.find_element_by_id('planner-button').click() # heading = self.browser.find_element_by_tag_name('h1') # self.browser.implicitly_wait(1) # self.assertEquals(heading.text, 'Planner') # self.browser.find_element_by_id('shopping-list-button').click() # heading = self.browser.find_element_by_tag_name('h1') # self.browser.implicitly_wait(1) # self.assertEquals(heading.text, 'Shopping List') # self.browser.find_element_by_id('search-button').click() # heading = self.browser.find_element_by_tag_name('h1') # self.browser.implicitly_wait(1) # self.assertEquals(heading.text, 'Search Recipes') search_field = self.browser.find_element_by_id('search-box') search_field.send_keys("apple pie") self.browser.find_element_by_id('search-recipes-button').click() try: element = WebDriverWait(self.browser, 10).until( ec.presence_of_element_located(By.CLASS_NAME('recipe-card'))) finally: self.browser.quit() # check if search exists # check if recipes exist recipe_results_list = self.browser.find_elements_by_class_name( 'recipe-card') self.assertEqual(len(recipe_results_list), 10)
def test_add_to_cart(driver): auth(driver) count = 1 while int(count) < 3: driver.find_element_by_css_selector('div.content img.image').click() time.sleep(2) if len( driver.find_elements_by_css_selector( 'a.main-image.fancybox.zoomable.shadow > div.sticker.sale') ) > 0: time.sleep(2) driver.find_element_by_css_selector( 'select[name="options[Size]"] > option[value="Small"]').click( ) time.sleep(2) driver.find_element_by_css_selector( 'button[name="add_cart_product"]').click() # time.sleep(2) wait.until( EC.text_to_be_present_in_element( By.CSS_SELECTOR('a.content span.quantity'), str(count))) count = driver.find_element_by_css_selector( 'span.quantity').get_attribute('innerText') driver.get("http://litecart/en/") else: driver.find_element_by_css_selector( 'button[name="add_cart_product"]').click() # time.sleep(2) wait.until( EC.text_to_be_present_in_element( By.CSS_SELECTOR('a.content span.quantity'), str(count))) count = driver.find_element_by_css_selector( 'span.quantity').get_attribute('innerText') driver.get("http://litecart/en/") driver.find_element_by_css_selector( 'a.link[href="http://litecart/en/checkout"]').click() driver.find_element_by_css_selector( 'button[name="remove_cart_item"]').click() driver.refresh() driver.find_element_by_css_selector( 'button[name="remove_cart_item"]').click() driver.refresh() driver.find_element_by_css_selector( 'button[name="remove_cart_item"]').click() driver.get("http://litecart/en/") time.sleep(5)
def get_following(self): """Gets the profiles that the user follows.""" followbutton = self.driver.find_element_by_partial_link_text("following") sleep(2) followbutton.click() follows = self.driver.find_elements(By.XPATH("//div[@class='wo9IH']")).get_attribute("title") for i in follows: print(i)
def is_no_password_validation_msg_displayed(self): is_msg_displayed = False parent = self._noPasswordValidationMsg().find_element( By.XPATH(str(self._parent_xpath))) classes = parent.get_attribute("class") if "has error" in classes: is_msg_displayed = True return is_msg_displayed
def select_car_type(self, car_type): """ Method to select a car type based on the input :return: """ try: temp_dict = {} price_list = [] lowest_price_vehicle_key = 0 self.driver.find_element_by_xpath( WEB_ELEMENt_VEHICLE_LIST_ARROW).click() self.driver.implicitly_wait(40) WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located( By.XPATH(SELECT_VEHICLE.format(car_type)))) self.driver.find_element_by_xpath(SELECT_VEHICLE).click() WebDriverWait(self.driver, 30).until( EC.visibility_of_element_located( By.XPATH(LIST_FILTERED_SUV_VEHICLES_ONLY))) filtered_vehicles = self.driver.find_elements_by_xpath( LIST_FILTERED_SUV_VEHICLES_ONLY) for vehilcle in filtered_vehicles: i = 1 seat_Numbers = filtered_vehicles.find_element_by_xpath( WEB_ELEMENT_FOUR_DOORS_LIST) DOOR_NUMBERS = filtered_vehicles.find_element_by_xpath( WEB_ELEMENT_FOUR_DOORS_LIST) PRICE = filtered_vehicles.find_element_by_xpath(PRICE_TEXT) temp_dict.update({i: PRICE}) price_list.append(PRICE) i = i + 1 min_price = min(price_list) for key in temp_dict.keys(): if temp_dict[key] == min_price: lowest_price_vehicle_key = key selected_vehicle_name = filtered_vehicles[ lowest_price_vehicle_key].find_element_by_xpath( SELECTED_VEHICLE_NAME).text select_vehicle = filtered_vehicles[ lowest_price_vehicle_key].find_element_by_xpath( SELECT_LOWEST_BUTTON).click() return selected_vehicle_name except Exception as err: logging.error("Issue in selecting the lowest price vehicle") return False
def wait_until_presents_by_CSS(self, css): try: self._logger.info("----- wait presence by : " + str(css) + " -----") return WebDriverWait(self._driver, 10).until( EC.presence_of_element_located((By.selector(css)))) except WebDriverException as e: self._logger.critical("'Invalid Input : " + str(e))
def find_elements(self, by=By.ID, value=None): if not By.is_valid(by) or not isinstance(value, str): raise InvalidSelectorException("Invalid locator values passed in") return self._execute(Command.FIND_CHILD_ELEMENTS, { "using": by, "value": value })['value']
def method(self, by=By.ID, value=None): if By.is_valid(by) and by == By.CLASS_NAME: by = By.CSS_SELECTOR value = "." + value if original.im_self: return original(by, value) else: return original(self, by, value)
def getAlert(self, driver, Writenotice): try: # /获取弹框 self.checkelement.Waitelement( driver, 20, By.xpath("//*[@class='alert-container']/div/div")) a = driver.findElement( By.xpath("//*[@class='alert-container']/div")).getAttribute( "class") except Exception as e: return True alerttext = driver.findElement( By.xpath("//*[@class='alert-container']/div/div")).getText() if a.contains("info") | a.contains("danger"): logging.error(Writenotice + alerttext) return False else: logging.info(Writenotice + alerttext) return True
def close_pop_up(self) -> bool: try: element = WebDriverWait(self.driver, 10) \ .until( method=EC.presence_of_element_located(By.XPATH("//div[contains(@class,'close-popup-activity')]"))) element.click() return True except: return False
def agree(self): try: WebDriverWait(self.browser, 3).until( EC.element_to_be_clickable( (By.XPATH('/html/body/div[2]/div/div[2]/div/div/button[1]') ))) except TimeoutException: print("不需要同意") pass
def find_elements(self, by=By.ID, value=None): """ 'Private' method used by the find_elements_by_* methods. :Usage: Use the corresponding find_elements_by_* instead of this. """ if not By.is_valid(by) or not isinstance(value, str): raise InvalidSelectorException("Invalid locator values passed in") return self.execute(Command.FIND_ELEMENTS, {'using': by, 'value': value})['value']
def test_auto_write_time_for_orange_python_webdriver(self): driver = self.driver driver.get(self.base_url + "/login.php") driver.find_element_by_name("txtUserName").clear() driver.find_element_by_name("txtUserName").send_keys(UserName) driver.find_element_by_name("txtPassword").send_keys(Password) driver.find_element_by_name("Submit").click() driver.find_element_by_link_text("Time").click() driver.find_element_by_link_text("Timesheets").click() driver.find_element_by_id("btnEdit").click() row_count=driver.findElement(By.tagName("tr")).size() print row_count
def find_elements(self, by=By.ID, value=None): if not By.is_valid(by) or not isinstance(value, str): raise InvalidSelectorException("Invalid locator values passed in") if by == By.ID: by = By.CSS_SELECTOR value = '[id="%s"]' % value elif by == By.TAG_NAME: by = By.CSS_SELECTOR elif by == By.CLASS_NAME: by = By.CSS_SELECTOR value = ".%s" % value elif by == By.NAME: by = By.CSS_SELECTOR value = '[name="%s"]' % value return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})['value']
def find_elements(self, by=By.ID, value=None): if not By.is_valid(by) or not isinstance(value, str): raise InvalidSelectorException("Invalid locator values passed in") return self._execute(Command.FIND_CHILD_ELEMENTS, {"using": by, "value": value})['value']
= 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0' ghost = webdriver.PhantomJS(executable_path='E:/software/phantomjs-2.1.1-windows/bin/phantomjs.exe') def get_param( driver, url ): driver.get(url) total_txt = driver.find_element_by_id("total").text #try: return total_txt if __name__ == '__main__': cid = 566921 url_address = "https://iknow.jp/courses/%d"%cid #total = get_param(ghost,url_address) # f = open("record.txt","wt+",encoding="UTF-8") #ofile_name = "record_%d.txt"%cid #ofile = codecs.open(ofile_name, "w", "utf-8") voclist = ghost.findElements(By.xpath("//li")) for i in voclist: print(i) #for j in range(0, total): current_page = ghost.find_element_by_css_selector('.items').text print("current page:" + current_page) k = 0 # get_transaction_from_page(ofile, ghost, int(current_page), total) ghost.close() #ofile.close()
def get_items(self) -> list: li_list = self.web_element.find_elements(By.xpath('/li')) return DomElementFactory.create_dom_element_list(li_list)
def get_parent(self): return self.web_element.find_element(By.xpath('..'))