def pressOnBlog(self): element = findElementByXpath(self.driver, '//span[@data-horizontal-title="Blog"]') clickAndOpenNewTab(self.driver, element) window = changeWindowAndSwitch(self.driver, 1) if not window: errorButton = f'The button:{element.text} was not pressed' raise Exception(errorButton) if self.driver.current_url == "https://supermelon.com/blog": listCategories = findElementByXpath( self.driver, '//ul[@class="list-categories"]') categories = getTagNames(listCategories, 'li') for category in categories: clickAndOpenNewTab(self.driver, category) textToSearch = category.text changeWindowAndSwitch(self.driver, 2) posts = findElementsByXpath( self.driver, '//div[@class="item post-categories"]') for post in posts: if textToSearch == post.text: self.driver.execute_script("window.close('');") changeWindowAndSwitch(self.driver, 1) break else: error = f"{textToSearch} web does not appear after press on {textToSearch}\n, the url is: {self.driver.current_url}" raise Exception(error) return True
def press(self): allIDS = [5412] n = 1 urlS = self.url.split("/id/") for id in allIDS: otherURL = f"{urlS[0]}/id/{id}" self.driver.get(otherURL) ssss111 = findElementByXpath(self.driver, '//div[@class="page-actions-inner"]') name = ssss111.get_attribute("data-title") name = name.split(" (") name = name[0] worksheet = self.workbook.add_worksheet(name) worksheet.write(0, 0, "product name") worksheet.write(0, 1, "sku") restart3 = True while restart3: try: elementList = findElementByXpath( self.driver, '//ul[@class="product-list ui-sortable"]') pressOnShowMore = True products = getTagNames(elementList, "li") restart3 = False except AttributeError as e: self.driver.get(otherURL) sleep(20) n3333 = 0 while True: for pro in products: n3333 += 1 if "automatic-sorting" in pro.get_attribute("class"): pressOnShowMore = False break else: getProdID = getTagNames(pro, "div") for i in getProdID: if i.get_attribute("class") == "info": prodID = getTagNames(pro, "p") for product in prodID: if product.get_attribute("class") == "sku": sku = product.text prodName = getTagName(pro, "h1") worksheet.write(n, 0, prodName.text) worksheet.write(n, 1, sku) n += 1 break if pressOnShowMore: print("the product have more name") break self.again = False
def pressOnReadyToShip(self, checkSpelling=None): element = findElementByXpath(self.driver, '//span[@data-horizontal-title="Ready to Ship"]') element.click() if not checkIfPopUpAppears(self.driver, "login"): error = f"login popup does not appear after press on {element.text}\n" raise Exception(error) return True
def pressOnAboutUS(self): element = findElementByXpath(self.driver, '//span[@data-horizontal-title="About"]') clickAndOpenNewTab(self.driver, element) errorAbout = f"about page does not appear after press on {element.text}\n the url was {self.driver.current_url}" window = changeWindowAndSwitch(self.driver, 1) if not window: errorButton = f'The button:{element.text} was not pressed' raise Exception(errorButton) if self.driver.current_url == "https://supermelon.com/about-us": sleep(2) startedButton = findElementByXpath(self.driver, '//a[@class="action button cms-signup-link"]') startedButton.click() if not checkIfPopUpAppears(self.driver, "enterprise"): error = f"login popup does not appear after press on {startedButton.text}\n" raise Exception(error) else: self.driver.execute_script("window.close('');") changeWindowAndSwitch(self.driver, 0) raise Exception(errorAbout) return True
def pressOnEachProduct(self): with open(f"{os.getcwd()}/Files/newTest/allURLS.csv", "r") as file: urls = file.read().splitlines() for url in urls: self.driver.get(url) # numOfPages = findElementsByXpath(self.driver, '//span[@class="toolbar-number"]') # numOfPage = int(numOfPages[2].text) / 20 # if not isinstance(numOfPage, int): # numOfPage = int(numOfPage) + 1 for num in itertools.count(start=1): if num > 5: break url = url.replace(url, f'{url}?p={str(num)}') self.driver.get(url) products = findElementsByXpath( self.driver, '//div[@data-container="product-grid"]') for gg, product in enumerate(products): productURL = getTagName(product, "a") productURL = productURL.get_attribute("href") self.driver.execute_script( f'''window.open("{productURL}","_blank");''') if gg == 3: break for number, window in enumerate(self.driver.window_handles): if number > 0: self.driver.switch_to.window(window) if not "Hello," in findElementByXpath( self.driver, '//span[@class="logged-in"]').text: LoginFeature(self.driver).checkLoginInFeature( skipOnSignInButton=True) findElementByXpath(self.driver, '//a[@class="MagicZoom"]') self.driver.execute_script("window.close('');") self.driver.switch_to.window(self.driver.window_handles[0]) url = url.replace(f"?p={str(num)}", "") print("next page ----------------------") print('next url ---------------------------')
def pressOnEachCategory(self): categories = getAllSubAndMainCategories(self.driver) for number, category in enumerate(categories): print(category.get_attribute("class")) if "popularcategories" in category.get_attribute("class"): subCategories = findElementsByXpath( category, '//span[@class="sm_megamenu_title_link"]') else: subCategories = findElementsByXpath( category, '//span[@class="sm_megamenu_title_lv-2"]') for number2, subCategory in enumerate(subCategories): getParentElement = findElementByXpath(subCategory, "..") className = getParentElement.get_attribute("class") if not "show-popup-signup" in className: print(className) print(getParentElement.text) error = f"login popup does not belongs to the element, the class name is: {className}\n" raise Exception(error) return True
def returnID(self): findElementByXpath( self.driver, '//input[@id="username"]').send_keys("categoryaccess") findElementByXpath(self.driver, '//input[@id="login"]').send_keys("Koshita1234#$%") el = findElementByXpath( self.driver, '//button[@class="action-login action-primary"]') el.click() n = 2 element = findElementsByXpath(self.driver, '//li[@class="x-tree-node"]') sssss = element[n] n2 = 0 name = '' here = True while True: element = findElementsByXpath(self.driver, '//li[@class="x-tree-node"]') if here: sssss = element[n] else: for na, s in enumerate(element): if name == getTagName(s, "a").text: sssss = element[na + 1] here = True break restart = True while restart: div = getTagName(sssss, 'div') if not "x-tree-node-leaf" in div.get_attribute("class"): print(div.get_attribute("class")) img = getTagNames(div, "img") for i in img: print(i.get_attribute("class")) if "plus" in i.get_attribute("class"): ul = getTagName(sssss, "ul") restart2 = True while restart2: try: i.click() restart2 = False except ElementClickInterceptedException as e: sleep(5) sssss = ul break elif "minu" in i.get_attribute("class"): ul = getTagName(sssss, "ul") sssss = ul break else: continue elif "x-tree-node-leaf" in div.get_attribute("class"): l1 = getTagNames(sssss, "li") l1[n2].click() self.url = self.driver.current_url restart = False if self.again: self.press() else: self.workbook.close() break