def from_search_goto_specific_currency(driver, currency): # if driver.find_element_by_xpath('//*[@id="search-header"]//*[@class="search-input"]'): # driver.find_element_by_xpath('//*[@id="search-header"]//*[@class="search-input"]').click() elemlist = driver.find_elements_by_id("navigation-search-button") hoover(driver).move_to_element_with_offset(elemlist[0], 10, 0).perform() elemlist[0].click() driver.find_element_by_xpath("//*[contains(text(),'Currencies')]").click() driver.find_element_by_xpath("//*[contains(text(),'Major')]").click() sleep(1) currency1 = currency.replace('/', '') xp_gbpusd = '//*[@data-code="' + currency1 + '"]//*[@class="ticker"]//*[@class="has-ellipsed-text"]' element1 = driver.find_element_by_xpath(xp_gbpusd) element1.click() print('\nCURRENCY = ', currency) sleep(1) xp_sell = '//*[@data-code="' + currency1 + '"]//*[@data-dojo-attach-point="mainViewNode"]//*[@data-dojo-attach-point="sellPriceNode"]' xp_buy = '//*[@data-code="' + currency1 + '"]//*[@data-dojo-attach-point="mainViewNode"]//*[@data-dojo-attach-point="buyPriceNode"]' print('SELL = ', driver.find_element_by_xpath(xp_sell).text, ' / BUY = ', driver.find_element_by_xpath(xp_buy).text) xp_low = '//*[@id="current-status-high-low-view"]//*[@data-dojo-attach-point="lowPriceNode"]' xp_high = '//*[@id="current-status-high-low-view"]//*[@data-dojo-attach-point="highPriceNode"]' print('LOW = ', driver.find_element_by_xpath(xp_low).text, ' / HIGH = ', driver.find_element_by_xpath(xp_high).text) return driver
def movearound_showtext(driver, element, x_value, y_value): hoover(driver).move_to_element_with_offset(element, x_value, y_value).perform() print() print('x = ', x_value, ' / y = ', y_value) print('NEWTEXT = ', " // ".join(element.text.split('\n')[0:3])) print('NEWLOCTN = ', element.location) print(' -- > to compare / DISPLAY_SIZE = ', driver.execute_script("return window.innerWidth"), ' x ', driver.execute_script("return window.innerHeight")) print() return int(element.location['x']), int(element.location['y'])
def movearound_showtext(driver, element, x_value, y_value, prev_text, value_EMA): hoover(driver).move_to_element_with_offset(element, x_value, y_value).perform() # print('x = ', x_value, ' / y = ', y_value) chktext = element.text.split('\n')[0].replace(' ', '') if chktext != prev_text: text = text_to_display(element.text.split('\n'), value_EMA) else: text = '' return int(element.location['x']), int( element.location['y']), text, chktext
def from_search_goto_specific_currency(driver, currency): # if driver.find_element_by_xpath('//*[@id="search-header"]//*[@class="search-input"]'): # driver.find_element_by_xpath('//*[@id="search-header"]//*[@class="search-input"]').click() elemlist = driver.find_elements_by_id("navigation-search-button") hoover(driver).move_to_element_with_offset(elemlist[0], 10, 0).perform() elemlist[0].click() driver.find_element_by_xpath("//*[contains(text(),'Currencies')]").click() driver.find_element_by_xpath("//*[contains(text(),'Major')]").click() sleep(1) currency1 = currency.replace('/', '') xp_gbpusd = '//*[@data-code="' + currency1 + '"]//*[@class="ticker"]//*[@class="has-ellipsed-text"]' element1 = driver.find_element_by_xpath(xp_gbpusd) element1.click() print('\nCURRENCY = ', currency) sleep(1) return driver
def from_search_goto_specific_currency(self, currency): self.log.info("-> " + inspect.stack()[0][3] + " started" + ' / CURRENCY = ' + currency) # self.driver.find_element_by_xpath('//*[@id="search-header"]//*[@class="search-input"]') # self.driver.find_elements_by_id("navigation-search-button") # self.driver.find_elements_by_xpath('//div[@id="navigation"]//div[@id="navigation-search-button" and @class="search-button"]/span') elemlist = self.driver.find_elements_by_css_selector('#navigation-search-button > span') hoover(self.driver).move_to_element_with_offset(elemlist[0], 10, 0).perform() elemlist[0].click() self.driver.find_element_by_xpath("//*[contains(text(),'Currencies')]").click() self.driver.find_element_by_xpath("//*[contains(text(),'Major')]").click() sleep(1) currency1 = currency.replace('/', '') xp_currency = '//*[@data-code="' + currency1 + '"]//*[@class="ticker"]//*[@class="has-ellipsed-text"]' element1 = self.driver.find_element_by_xpath(xp_currency) element1.click() print(currency, end=' ') sleep(0.5)
def baca_graff(): print('\nTEST BACA GRAFF') xp_baca = '//*[((@class="chart-container") or (@class="chart-container draggable")) and (@tabindex="-1")]' list1 = driver.find_elements_by_xpath(xp_baca) print('number of elements = ', len(list1)) features_el = list1[-1] id1 = features_el.get_attribute('class') print('ID1 = ', id1) hoover(driver).move_to_element(features_el).perform() currenturl = driver.current_url print('currentURL = ', currenturl) # print() text123 = dapatkan_values() # print(text123) return text123
def movearound_showtext(driver, element, x_value, y_value, prev_text, value_EMA): hoover(driver).move_to_element_with_offset(element, x_value, y_value).perform() chktext = element.text.split('\n')[0].replace(' ', '') try: if chktext == prev_text: text = 'duplicate' elif str(element.text.split('\n')[4]) == 'Close': text = 'xlocation / ' + str( element.location['x']) + ' / ylocation / ' + str( element.location['y']) else: text = text_to_display(element.text.split('\n'), value_EMA) except: text = 'out_of_boundary_or_wrong_value' return int(element.location['x']), int( element.location['y']), text, chktext
for ele in chkelements2: # driver.execute_script("arguments[0].scrollIntoView(true); window.scrollBy(100,0);", ele) test1 = '//*[@class="chart-tooltip"]' # test1 = '//*[@class="chart-container"]' toolTip = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.XPATH, test1))) # xx1 = toolTip.location['x'] # toolTip = WebDriverWait(driver, 10).until(EC._find_elements(driver)) # gtattb = 'style' # print('toolTip get_attrb', gtattb, '= ', toolTip.get_attribute(gtattb)) # print('\nCHECK JER NI') # print('toolTip TYPE = ', type(toolTip)) # print('EC_presence_of_ele_loc TYPE = ', type(EC.presence_of_element_located((By.XPATH, test1)))) # print() hoover(driver).move_to_element(toolTip).perform() # driver.execute_script("window.scrollTo(100,0);") print('ELE LOCATION ', toolTip.location, ' / y = ', toolTip.location['y']) yy1 = toolTip.location['y'] xx1 = toolTip.location['x'] print('TEXT2 = \n', " // ".join(toolTip.text.split('\n')[0:3])) all_children_by_xpath = toolTip.find_elements_by_xpath(".//*") print('len(all_children_by_xpath): ', len(all_children_by_xpath)) print('TEXT 0 = \n', " // ".join(all_children_by_xpath[0].text.split('\n')[0:3])) # print('TEXT TGH = \n', " // ".join(all_children_by_xpath[int(len(all_children_by_xpath)/2)].text.split('\n')[0:3])) # print('TEXT -1 = \n', " // ".join(all_children_by_xpath[-1].text.split('\n')[0:3])) # print('TEXT 0 get_attrb = ', all_children_by_xpath[0].get_attribute('class'))
def test_one(self): driver = self.driver current1 = strftime("%Y-%m-%d %H:%M:%S") if driver.name == 'chrome': driver.maximize_window() driver.get(self.base_url) driver.find_element_by_name('q').click() driver.find_element_by_name('q').send_keys("pixitmedia" + Keys.ENTER) list_pixitmedia = driver.find_elements_by_xpath("//*[contains(text(),'Pixit Media')]") self.assertGreaterEqual(len(list_pixitmedia), 1) # OLD code - not working anymore # for element in list_pixitmedia: # if element.text == "https://www.pixitmedia.com/": # element.click() # if driver.find_element_by_xpath("//*[contains(text(),'https://www.pixitmedia.com/')]").text == "https://www.pixitmedia.com/": # driver.get("https://www.pixitmedia.com/") list_pixitmedia[0].click() basepixitmediaurl = driver.current_url print('PIXITMEDIA URL = ' + str(basepixitmediaurl)) elements_pixstor = driver.find_elements_by_xpath("//*[contains(text(),'PixStor')]") self.assertGreaterEqual(len(elements_pixstor), 1) element_pixstor = elements_pixstor[0] hoover(driver).move_to_element(element_pixstor).perform() features_el = driver.find_element_by_xpath("//*[contains(text(),'Features')]") hoover(driver).move_to_element(features_el).perform() powersearch_el = driver.find_element_by_xpath("//*[contains(text(),'Powerful Search')]") hoover(driver).move_to_element(powersearch_el).perform() powersearch_el.click() driver.get(basepixitmediaurl) element_comp = driver.find_elements_by_xpath("//*[contains(text(),'Company')]")[0] hoover(driver).move_to_element(element_comp).perform() resc_el = driver.find_element_by_xpath("//*[contains(text(),'Resources')]") hoover(driver).move_to_element(resc_el).perform() resc_el.click() if driver.find_elements_by_xpath("//*[contains(text(),'Data Sheets')]"): driver.execute_script("window.scrollTo(0, " + str(self.displayheight()[2]) + ");") driver.find_elements_by_xpath("//*[contains(text(),'Data Sheets')]")[0].click() else: driver.find_elements_by_xpath("//*[contains(text(),'Data Sheets')]")[0].click() driver.execute_script("window.scrollTo(0, " + str(self.displayheight()[1]) + ");") sleep(2) pixstor_overview = driver.find_elements_by_xpath("//*[contains(text(),'PixStor Overview')]") if len(pixstor_overview) >= 1: print('PixStor Overview PDF FOUND!!!') print('Element text = ' + str(pixstor_overview[0].text)) pixstor_overview[0].click() # View Datasheet - PDF file if driver.find_element_by_xpath("//*[contains(text(),'DOWNLOAD')]"): driver.execute_script("window.scrollTo(0, " + str(self.displayheight()[2]) + ");") pdffileurl = driver.find_element_by_xpath("//*[contains(text(),'DOWNLOAD')]").get_attribute('href') print('PDF FILE URL = ' + str(pdffileurl)) # validate PDF file wget.download(pdffileurl, out=self.tmpfilename) file1 = open(self.tmpfilename, "rb") chkfile = fleep.get(file1.read(128)) # print('TYPE = ' + str(chkfile.type)) print('EXTN = ' + str(chkfile.extension)) print('MIME = ' + str(chkfile.mime)) self.assertIn('pdf', str(chkfile.mime)) file1.close() else: print('PixStor Overview PDF NOT FOUND') # Contact Us Form driver.get(basepixitmediaurl) driver.find_element_by_xpath("//*[contains(text(),'Contact Us')]").click() # print("URL Contact Us = " + str(driver.current_url)) driver.execute_script("window.scrollTo(0, " + str(self.displayheight()[1]) + ");") # All data to send name1 = 'Cromox' name2 = 'One' email1 = '*****@*****.**' comp1 = 'Ranorexxx' phone1 = "07769916425" subject1 = 'Test1' print('NAME : ' + name1 + ' ' + name2) print('EMAIL : ' + email1 + ' / PHONE : ' + phone1) print('COMPANY : ' + comp1) print('SUBJECT : ' + str(subject1)) # fill-in the form element_firstname = driver.find_element_by_name('input_1.3') hoover(driver).move_to_element(element_firstname).perform() element_firstname.clear() element_firstname.send_keys(name1) element_lastname = driver.find_element_by_id("input_2_1_6") hoover(driver).move_to_element(element_lastname).perform() # element_lastname.click() element_lastname.clear() element_lastname.send_keys(name2) element_email = driver.find_element_by_id("input_2_2") hoover(driver).move_to_element(element_email).perform() # element_email.click() element_email.clear() element_email.send_keys(email1) element_company = driver.find_element_by_id("input_2_3") hoover(driver).move_to_element(element_company).perform() element_company.clear() element_company.send_keys(comp1) element_phone = driver.find_element_by_id("input_2_7") hoover(driver).move_to_element(element_phone).perform() element_phone.clear() element_phone.send_keys(phone1) element_subject = driver.find_element_by_id("input_2_4") hoover(driver).move_to_element(element_subject).perform() element_subject.clear() element_subject.send_keys(subject1) element_message = driver.find_element_by_id("input_2_6") hoover(driver).move_to_element(element_message).perform() element_message.clear() current2 = strftime("%Y-%m-%d %H:%M:%S") message1 = "This is a test for Jez \n\nToday is " + str(current2) + \ '\nExact testing time : From ' + str(current1) + ' to ' + str(current2) + \ "\nThis Earth of Mankind (Bumi Manusia) -> is it Jez?? " \ "\nI don't think so. Look at the inconsiderate you!!" print('MESSAGE :\n' + str(message1)) element_message.send_keys(message1) # Half page scroll down driver.execute_script("window.scrollTo(0, " + str(self.displayheight()[1]) + ");") driver.find_element_by_name('input_8.1').click() element_send = driver.find_element_by_xpath("//*[@value='Send']") self.assertIsNotNone(element_send) hoover(driver).move_to_element(element_send).perform() element_send.click()
driver.find_element_by_xpath("//*[contains(text(),'5 minutes')]").click() print('END 3 - time period 5 mins') ## baca graph print('\nTEST123 - baca graf') # xp_baca = "//*[contains(text(),'31.12.2020 22:00')]" # xp_baca = '//*[@class="chartLayer"]' xp_baca = '//*[((@class="chart-container") or (@class="chart-container draggable")) and (@tabindex="-1")]' list1 = driver.find_elements_by_xpath(xp_baca) # print() # print('number of elements = ', len(list1)) features_el = list1[-1] hoover(driver).move_to_element(features_el).perform() currenturl = driver.current_url print('currentURL = ', currenturl) # datasource = driver.page_source # print('DATA = \n', datasource) # powersearch_el = driver.find_element_by_xpath("//*[contains(text(),'31.12.2020 22:00')]") # print('TEXT', powersearch_el.text) # element2 = driver.find_element_by_xpath("//*[contains(text(),'31.12.2020 22:00')]") # driver.execute_script("arguments[0].click();", element2) # if normal click not working, this is JS click ## NI NOTE JER # 6) Hoover mouse # # basepixitmediaurl = driver.current_url
def test_one(self): driver = self.driver if driver.name == 'chrome': driver.maximize_window() driver.get(self.base_url) driver.find_element_by_name('q').click() driver.find_element_by_name('q').send_keys("pixitmedia" + Keys.ENTER) list_pixitmedia = driver.find_elements_by_xpath("//*[contains(text(),'Pixit Media')]") # for element in list_pixitmedia: # if element.text == "https://www.pixitmedia.com/": # element.click() # if driver.find_element_by_xpath("//*[contains(text(),'https://www.pixitmedia.com/')]").text == "https://www.pixitmedia.com/": # driver.get("https://www.pixitmedia.com/") list_pixitmedia[0].click() basepixitmediaurl = driver.current_url print('PIXITMEDIA URL = ' + str(basepixitmediaurl)) # Products -- HAS EXPIRED & HAS CHANGED # driver.find_element_by_xpath('//*[@id="menu-item-48"]/a/span').click() # PixStor -- HAS EXPIRED & CHANGED... NOW USE HOOVER # driver.find_element_by_link_text('PixStor').click() # driver.find_element_by_link_text("PixStor Search").click() element_pixstor = driver.find_elements_by_xpath("//*[contains(text(),'PixStor')]")[0] hoover(driver).move_to_element(element_pixstor).perform() features_el = driver.find_element_by_xpath("//*[contains(text(),'Features')]") hoover(driver).move_to_element(features_el).perform() powersearch_el = driver.find_element_by_xpath("//*[contains(text(),'Powerful Search')]") hoover(driver).move_to_element(powersearch_el).perform() powersearch_el.click() # # View Datasheet - PDF file -- NOW NO LONGER EXIST !!!! # driver.find_element_by_xpath("//span[@class='elementor-button-text']").click() # # ## validate PDF file # currenturl = driver.current_url # req = urlget(currenturl) # # validate1 - simple by check header # self.assertGreater(int(req.headers['Content-Length']), 1000) # self.assertEqual(req.headers['Content-Type'], 'application/pdf') # # validate2 - download & check file using PyPDF2 # file1 = open(self.tmpfilename, "wb") # file1.write(req.content) # pdfproducer = PDFread(self.tmpfilename).getDocumentInfo().producer # file1.close() # pdfchklist = ['Adobe', 'PDF', 'Acrobat'] # words to confirm PDF # listintrsect = [x.upper() for x in pdfchklist if x.upper() in pdfproducer.upper()] # self.assertGreaterEqual(len(listintrsect), 1) # Contact Us Form driver.get(basepixitmediaurl) driver.find_element_by_xpath("//*[contains(text(),'Contact Us')]").click() # print("URL Contact Us = " + str(driver.current_url)) # Full Page scroll down # driver.find_element_by_xpath("//*[contains(text(),'Contact Us')]").send_keys(Keys.PAGE_DOWN) # driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") # driver.execute_script("window.scrollTo(0, Y)") # Half page scroll down try: last_height = driver.execute_script("return document.body.scrollHeight") except: last_height = 1800 if last_height <= 1800: last_height = 1900 print('HEIGHT = ' + str(last_height)) one_height = int(0.5 * last_height) print('0.5HEIGHT = ' + str(one_height)) driver.execute_script("window.scrollTo(0, " + str(one_height) + ");") element_firstname = driver.find_element_by_name('input_1.3') hoover(driver).move_to_element(element_firstname).perform() element_firstname.clear() element_firstname.send_keys('Rosli') element_lastname = driver.find_element_by_id("input_2_1_6") hoover(driver).move_to_element(element_lastname).perform() # element_lastname.click() element_lastname.clear() element_lastname.send_keys("Talib") element_email = driver.find_element_by_id("input_2_2") hoover(driver).move_to_element(element_email).perform() # element_email.click() element_email.clear() element_email.send_keys("*****@*****.**") element_company = driver.find_element_by_id("input_2_3") hoover(driver).move_to_element(element_company).perform() element_company.clear() element_company.send_keys("Ranorexxx") element_phone = driver.find_element_by_id("input_2_7") hoover(driver).move_to_element(element_phone).perform() element_phone.clear() element_phone.send_keys("07777999111") element_subject = driver.find_element_by_id("input_2_4") hoover(driver).move_to_element(element_subject).perform() element_subject.clear() element_subject.send_keys("Test1") element_message = driver.find_element_by_id("input_2_6") hoover(driver).move_to_element(element_message).perform() element_message.clear() element_message.send_keys("This is a test for Jez") # Half page scroll down driver.execute_script("window.scrollTo(0, " + str(one_height) + ");") driver.find_element_by_name('input_8.1').click() element_send = driver.find_element_by_xpath("//*[@value='Send']") hoover(driver).move_to_element(element_send).perform() element_send.click()