I have written a python script that communicates with the web page and makes an online order. In addition to that I have added some GUI, which allows the user to select the day of the order. Here is the python script
import easygui
import sys
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
import tkinter as tk
import tkinter.font as tkFont
badge_number = 111111
# Widget pop up for selection of the order day
root = tk.Tk()
def center_window(w=300, h=200):
# get screen width and height
ws = root.winfo_screenwidth()
hs = root.winfo_screenheight()
# calculate position x, y
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
root.geometry('%dx%d+%d+%d' % (w, h, x, y))
root.geometry("400x450")
Label = tk.Label(root, text = "Select lunch Order Day", font = ("Helvetica", 15))
Label.pack(pady=50, padx=40)
helv15 = tkFont.Font(family = "Helvetica", size = 15)
root.lift()
v = tk.StringVar()
v.set("Today")
tk.Label(root, textvariable = v).pack()
def close_window():
root.destroy()
today = tk.Radiobutton(root, text = "Today", variable = v, value = "Today", font = helv15).pack()
tomorrow = tk.Radiobutton(root, text = "Tomorrow", variable = v, value = "Tomorrow", font = helv15).pack()
cancel = tk.Radiobutton(root, text = "Cancel", variable = v, value = "Cancel", font = helv15).pack()
submit = tk.Button(root, text = "Submit", command = close_window, font = helv15).pack()
center_window(400, 400)
root.mainloop()
if v.get() == "Cancel":
sys.exit("Ordering was terminated")
driver = webdriver.Chrome(executable_path = "C:\webdrivers\chromedriver.exe")
driver.get("http://web_page/")
element = driver.find_element_by_name('employee_id')
element.send_keys(badge_number)
driver.find_element_by_xpath("/html/body/section/header/form/div/button").click()
# /html/body/section/header/form/div/button
delay = 60
todayBut = "/html/body/section/div[1]/div[2]/div/div/div/span[2]/span[1]/form/button"
tomorBut = "/html/body/section/div[1]/div[2]/div/div/div/span[1]/span[1]/form/button"
favorButToday = "/html/body/section/div/div[1]/button"
favorButTomor = "/html/body/section/div/div[1]/button/a"
myFavOrderID = "fav_order_view"
try:
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, todayBut)))
except TimeoutException:
print ("Loading Day Selection page took too much time!")
if v.get() == "Today":
driver.find_element_by_xpath(todayBut).click()
#favorite choice
try:
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, favorButToday)))
driver.find_element_by_xpath(favorButToday).click()
try:
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.ID, myFavOrderID)))
driver.find_element_by_id(myFavOrderID).click()
### select floor, order date and order now
select_floor = Select(driver.find_element_by_name("floor_number"))
select_floor.select_by_index("9")
select_day = Select(driver.find_element_by_name("order_date"))
select_day.select_by_value("today")
orderNowBtn = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
driver.find_element_by_xpath(orderNowBtn).click()
print("Today's order was successfully made!")
except TimeoutException:
print ("Loading Favorites page took too much time!")
except TimeoutException:
print ("Loading took too much time!")
else:
driver.find_element_by_xpath(tomorBut).click()
#favorite choice
try:
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.XPATH, favorButTomor)))
driver.find_element_by_xpath(favorButTomor).click()
try:
myFavOrderIDTomor = "fav_order_view"
element = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.ID, myFavOrderIDTomor)))
driver.find_element_by_id(myFavOrderIDTomor).click()
### select floor, order date and order now
select_floor = Select(driver.find_element_by_name("floor_number"))
select_floor.select_by_index("9")
select_day = Select(driver.find_element_by_name("order_date"))
select_day.select_by_value("tomorrow")
orderNowBtnTomor = "/html/body/div[1]/div[2]/div/div/div[3]/form/button"
driver.find_element_by_xpath(orderNowBtnTomor).click()
print("Tomorrow's order was successfully made!")
except TimeoutException:
print ("Loading Favorites page took too much time!")
except TimeoutException:
print ("Loading took too much time!")
However, I wanted to have it as an .exe file to run it with just double-click from my desktop. So, I have installed pyinstaller from git and run the simple line in the cmd (pyinstaller.exe --onefile --windowed --icon=app.ico LunchOrder.py). Unfortunately, the .exe isn't doign anything, it just pops up the "Fatal error detected" message, without any GUI (that I have written into the script itself). Any help would be appreciated!
Here i will tell you a better way to make .py to .exe . First make sure your python is added to system PATH, which i assume is. If not check some tutorials on how to add python to PATH then you can open your cmd and type in:
pip install pyinstaller
After this, you go to your path where the LunchOrder.py exists and open a cmd there, in windows you can type simply type in cmd in the address bar (after clearing adressbar), or else open a cmd and navigate to your path where LunchOrder.py file exists and simply type in:
pyinstaller -w -F -i "app.ico" LunchOrder.py
This should make a folder dist inside which your .exe will be there. MAKE SURE TO COPY THE .exe to outside the dist folder and run it there. Or else you might still get fatal error message. You can delete all the other extra files that was generated like build and LunchOrder.spec . If it still gives you error try following this method https://www.youtube.com/watch?v=OZSZHmWSOeM
Related
Is it possible to create a random selection of 2 arguments(with a choice of percentage of a certain argument) and in the event of a popup, the code skipped?
My code:
browser = uc.Chrome()
options = uc.ChromeOptions
options.headless = True
browser.get(home_url)
email_field = browser.find_element(By.XPATH, content)
email_field.click()
sleep(1)
search_login_window = browser.find_element(By.XPATH, login_windows)
search_login_window.send_keys(username)
find_place_email = browser.find_element(By.XPATH, email_login)
find_place_email.click()
sleep(2)
search_pass_window = browser.find_element(By.XPATH, password_windows)
search_pass_window.send_keys(password)
find_place_password = browser.find_element(By.XPATH, password_login)
find_place_password.click()
sleep(10)
I don't understand entirely what you mean since you didn't give any context in your code about where the popup would be, or what arguments you want to want to be dynamic, but here is a way to pick a random choice from a dict (which can be used as args)
import numpy as np
test = {"a": 1, "b": 2}
print(np.random.choice(list(test.keys()), p=[0.10, 0.90]))
I'm using the below code to get the current element at a cursor position, even if that element is within several iframes. I have two questions though.
Are all iframes located within an "iframe" tag as would be needed for the below code to work? If not, is there a more accurate way to do what I'm trying to do below?
How can I define the current iframe so that I can reliably return that identifier and find the same iframe next time the program is run? The element ID and session ID change each time the program is run, so if I were to manually save the iframe and use it to driver.switch_to.frame(element) next time the program ran, I know it wouldn't find it. So how can I make sure I'm in the correct iframe when locating an element after finding it this way?
Edit: To clarify, I'm attempting to create a script that works universally with any website, so the HTML of the website in this code would not be useful to include. That's why I wanted to know if all websites with iframes must use an "iframe" tag, or if there are some websites that this approach wouldn't work?
from selenium import webdriver
from tkinter import *
from pynput import mouse
from pynput.mouse import Listener
import time
def CheckRightClick(x, y, button, pressed):
if button == mouse.Button.right:
if pressed:
# Browser window position calculation script
coordinate_script = """
var X, Y;
if (window.screenY)
{
X = window.screenX;
Y = window.screenY + 124;
}
else
{
var Elem = document.documentElement;
if (!Elem.clientHeight) Elem = document.body;
X = Elem.scrollLeft;
Y = Elem.scrollTop;
}
return new Array(X, Y);
"""
print('Getting element')
driver.switch_to.default_content()
winPos = driver.execute_script(coordinate_script)
# actual element position in browser
x -= winPos[0]
y -= winPos[1]
driver.implicitly_wait(30)
element = driver.execute_script("""
return document.elementFromPoint(arguments[0], arguments[1]);
""", x, y)
# element = findElement(x, y)
deepestElement = None
if element is None:
print('current cursor position might be wrong')
return
if element is not None:
print(" id=> ", element.get_attribute("id"), "\n tagName=> <", element.tag_name, ">", "\n text=> ", element.text, "\n\r")
if element.tag_name == "iframe":
# get iframe element position. it will return {top: , left:, x: , y: , width: , height}
elementPos = driver.execute_script("""
var element = document.elementFromPoint(arguments[0], arguments[1]);
if(element !== null)
return element.getBoundingClientRect();
else
return null;
""", x, y)
# actual element postion in the iframe.
x -= elementPos['left']
y -= elementPos['top']
driver.switch_to.frame(element)
deepestElement = driver.execute_script("""
return document.elementFromPoint(arguments[0], arguments[1]);
""", x, y)
else:
deepestElement = element
if deepestElement is not None:
print("deepest element:\n id=> ", deepestElement.get_attribute("id"), "\n tagName=> <", deepestElement.tag_name, ">", "\n text=> ", deepestElement.text, "\n\r")
print('Element at cursor is ', deepestElement, "\n\r")
#deepestElement.click()
# click_window.event_generate("<<quit>>")
options = webdriver.ChromeOptions()
options.add_experimental_option('excludeSwitches', ['enable-logging'])
# driver = webdriver.Chrome(options=options, executable_path=r'./chromedriver_90.exe')
driver = webdriver.Chrome(options=options,executable_path=r'C:\Users\David\Desktop\Python\chromedriver_win32'r'\chromedriver.exe')
url = 'http://store.cardsagainsthumanity.com/'
driver.get(url)
time.sleep(3)
click_window = Tk()
click_prompt = Label(click_window, text='Right click somewhere')
click_prompt.grid(row=3, column=3)
click_window.bind("<<quit>>", lambda *args: click_window.destroy())
listener = Listener(on_click=CheckRightClick)
listener.start()
click_prompt.mainloop()
listener.stop()
I'm trying to save a website as PDF through printing dialog. My code allows me to save as pdf, but asks me to input a filename, which I don't know how to pass a filename to the pop up box.
Attached is my code:
import time
from selenium import webdriver
import os
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
self.profile.set_preference("pdfjs.disabled", True)
self.profile.set_preference("print.always_print_silent", True)
self.profile.set_preference("print.show_print_progress", False)
self.profile.set_preference("browser.download.show_plugins_in_list",False)
foxdriver = r'C:\Users\AShen\Documents\Workspace\geckodriver.exe'
self.driver = webdriver.Firefox(executable_path=foxdriver,firefox_profile = self.profile)
time.sleep(5)
def get_page_and_print(self, page):
self.driver.get(page)
time.sleep(5)
self.driver.execute_script("window.print();")
if __name__ == "__main__":
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.google.com/')
These days I had the same question.
I solved it without using the pyautogui in these case, because I use different PCs and monitors and I didn't want to depend on the position of the click.
I was able to solve it using the about:config... changing them with each necessary print (in PDF).
The name of my printer "in PDF" in Ubuntu is "Print to File" (defined in print_printer) and the settings of about:config need to be this printer...
For example: print.printer_Print_to_File.print_to_file: true
import os
import time
from selenium import webdriver
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference('services.sync.prefs.sync.browser.download.manager.showWhenStarting', False)
self.profile.set_preference('pdfjs.disabled', True)
self.profile.set_preference('print.always_print_silent', True)
self.profile.set_preference('print.show_print_progress', False)
self.profile.set_preference('browser.download.show_plugins_in_list', False)
self.profile.set_preference('browser.download.folderList', 2)
self.profile.set_preference('browser.download.dir', '')
self.profile.set_preference('browser.download.manager.showWhenStarting', False)
self.profile.set_preference('browser.aboutConfig.showWarning', False)
self.profile.set_preference('print.print_headerright', '')
self.profile.set_preference('print.print_headercenter', '')
self.profile.set_preference('print.print_headerleft', '')
self.profile.set_preference('print.print_footerright', '')
self.profile.set_preference('print.print_footercenter', '')
self.profile.set_preference('print.print_footerleft', '')
self.profile.set_preference('browser.helperApps.neverAsk.saveToDisk', 'application/octet-stream;application/vnd.ms-excel;text/html')
foxdriver = r'C:\Users\AShen\Documents\Workspace\geckodriver.exe'
self.driver = webdriver.Firefox(
executable_path=foxdriver,
firefox_profile=self.profile
)
time.sleep(1)
def get_page_and_print(self, page, filepath):
# Get about:config
self.driver.get('about:config')
time.sleep(1)
# Define Configurations
script = """
var prefs = Components.classes['#mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref('print.always_print_silent', true);
prefs.setCharPref('print_printer', 'Print to File');
prefs.setBoolPref('print.printer_Print_to_File.print_to_file', true);
prefs.setCharPref('print.printer_Print_to_File.print_to_filename', '{}');
prefs.setBoolPref('print.printer_Print_to_File.show_print_progress', true);
""".format(filepath)
# Set Configurations
self.driver.execute_script(script)
time.sleep(1)
# Get site to print in pdf
self.driver.get(page)
time.sleep(2)
self.driver.execute_script("window.print();")
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.google.com', os.path.join(os.getcwd(), 'mywebpage.pdf'))
Oh, it is very easy if you know about pyautogui.
This is an amazing module that allows you to automate your curser.
So essentially, you need to figure out the place where the popup appears and use pyautogui to click it for you.
All you need to add is:
time.sleep(3)
i=random.randint(0,1000)
file_name=('name_pdf '+str(i))
print (file_name)
pyautogui.typewrite(file_name)
pyautogui.click(512,449)
Entire code structure will look like this:
import time
import pyautogui
from selenium import webdriver
import os
class printing_browser(object):
def __init__(self):
self.profile = webdriver.FirefoxProfile()
self.profile.set_preference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", False)
self.profile.set_preference("pdfjs.disabled", True)
self.profile.set_preference("print.always_print_silent", True)
self.profile.set_preference("print.show_print_progress", False)
self.profile.set_preference("browser.download.show_plugins_in_list",False)
foxdriver = r'C:\Users\Pranjal Pathak\Desktop\Titanic Kaggle\geckodriver.exe'
self.driver = webdriver.Firefox(executable_path=foxdriver,firefox_profile = self.profile)
time.sleep(5)
def get_page_and_print(self, page):
self.driver.get(page)
time.sleep(5)
self.driver.execute_script("window.print();")
if __name__ == "__main__":
browser_that_prints = printing_browser()
browser_that_prints.get_page_and_print('http://www.python.org/')
time.sleep(3)
i=random.randint(0,1000)
file_name=('name_pdf '+str(i))
print (file_name)
pyautogui.typewrite(file_name)
pyautogui.click(512,449)
Note: 1. I have selected the name of the file as name+any random integer between 1 to 1000 to change name every time you save the file. This way it will save every time you run the code as the names will be different every time.
If this types the name but does not save the file, you might want to change the coordinates of your curser. Let me know if that happens.
I would like to get a screenshot of a full web page with Selenium python. To do that I used this answer.
But now I would like to divide the screenshot and limit the height of the resulting screenshot to 30 000px. For example, if a webpage height is 40 000px, I would like a first 30 000px screenshot and then a 10 000 px screenshot.
The solution should not be to save the full page and then crop the image, because I need it to work for very long webpages. Indeed it is not possible to get a screenshot with 120 000px height or you get this kind of error :
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://marionette/content/capture.js :: capture.canvas :: line 154" data: no]
I tried this but it does not wok at all :
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from time import sleep
def save_screenshot(d, path):
max_size = 30000
original_size = d.get_window_size()
required_width = d.execute_script('return document.body.parentNode.scrollWidth')+74
required_height = d.execute_script('return document.body.parentNode.scrollHeight')+74
if required_height <= max_size:
d.set_window_size(required_width, required_height)
d.find_element_by_tag_name('body').screenshot(path) # avoids scrollbar
else :
for i in range(0,int(required_height/max_size)):
d.set_window_position(0,max_size*i)
d.set_window_size(required_width, max_size)
d.find_element_by_tag_name('body').screenshot(path.replace(".png",str(i+1)+".png"))
d.set_window_position(0,max_size*int(required_height/max_size))
d.set_window_size(required_width, required_height%max_size)
d.find_element_by_tag_name('body').screenshot(path.replace(".png",str(int(required_height/max_size)+1)+".png"))
d.set_window_position(0,0)
d.set_window_size(original_size['width'], original_size['height'])
if __name__ == '__main__':
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options,executable_path=r"C:/Users/path/geckodriver.exe")
driver.get("http://www.lwb.com/")
sleep(3)
save_screenshot(driver,"C:/Users/path/test.png")
driver.close()
Can someone help me here please ?
Thank you,
Mylha
you can crop the saved screenshot using pillow pip install pillow
def crop_image(img, img_limit):
img_width, img_height = img.size
crop_dim = (0, 0, img_width, img_limit) # left top right bottom
cropped_img = img.crop(crop_dim)
return cropped_img
after doing save_screenshot(driver, "path/to/img"), do the following :
from PIL import Image
img_limit = 30000 # your image size limit
img = Image.open("path/to/img")
img = crop_image(img, img_limit)
img.save("path/to/img")
if you don't want to save the image before you manipulate it you can use get_screenshot_as_png, which will return binary data instead of saving it :
from PIL import Image
from io import BytesIO
img_limit = 30000 # your image size limit
img_binary = driver.get_screenshot_as_png()
img = Image.open(BytesIO(img_binary))
img = crop_image(img, img_limit)
img.save("path/to/save")
make sure to do del img and del img_binary when you're done to delete the binary data from memory
in order to take one screenshot of the entire page, do this:
from selenium import webdriver
DRIVER_PATH = "path/to/chrome/driver"
URL = "site.url"
options = webdriver.ChromeOptions()
options.add_argument("headless")
driver = webdriver.Chrome(executable_path = DRIVER_PATH, chrome_options = options)
# setting a long window height to take one full screenshot
driver.set_window_size(1920, 90000) # width , height
driver.get(URL)
driver.maximize_window()
img_binary = driver.get_screenshot_as_png()
PS : if you use this method to take the screenshot, you won't need pillow. simply use set_window_size to set the height and width of the window that you want, which will get you that same size in the screenshot
I'm trying to design an automation process that reads the value of a cell in an excel document, copies the value into a variable, and that variable is is pasted into a search box on a site. When the process is called again it goes to the next line, gets the new cell value, and searches again. However I can't seem to get it right in the slightest!
*Edit 7/21/2016
My current problem now is that on every iteration of the code the previous cell and new cell values are pasted. For example the first cell is 42-7211 and the second cell is 45-7311 and on the next time the function is called it pastes " 42-721145-7311 " not "45-7311"
Here is my full updated code. Once i get to the proper screen I use the function
prod_choose_searchbar to paste and then call stp to go to the next cell.
My Code UPDATED
import unittest
import xlrd
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium import *
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException
from datetime import date
from datetime import timedelta
import time
from time import sleep
def yesterday():
# Get today.
today = date.today()
# Subtract timedelta of 1 day.
yesterday = today - timedelta(days=1)
return yesterday
import logging
#start logging module this will record all actions and record them for debugging purposes!
LOG_FILENAME = 'log_file_selenium.txt'
logging.basicConfig(filename=LOG_FILENAME, level=logging.DEBUG)
logging.debug('This message should go to the log file')
#clear window
os.system('cls')
#open EXCEL
#Start classes
#define variables to call for automation process
#this will help run faster so the code is shorter in the main sections
"""
Used to read cells from an excel file one at a time
Use:
1) Call the class with new()
2) Call new.var() to clear variables and start at top of document
3) Call new.stp() to begin process
4) Call new.nextp() until finished
"""
#########################################################################
#########################################################################
class calls_sms():
def __init__(self): #sets variables up and inital value NULL
self.w = None
self.variable = None
self.value = None
self.default_int = 0 #
self.default_string = None #These are for empty feilds
self.default = None #
#open EXCEL
self.file_location = "C:\\Users\\doarni\\Desktop\\T0088Transfer.xls"
self.workbook = xlrd.open_workbook(self.file_location)
self.sheet = self.workbook.sheet_by_index(0)
#Excel interaction
def beginprod(self):
self.w = 1
calls_sms.stp(self)
def stp(self):
for row in range(self.sheet.nrows):
row = self.sheet.row_values(self.w)
self.variable = None
self.variable = row[7]
self.w += 1
return row[7]
#abbreviations for later use
def var(self): #must be called var, driver is not defined till launch call
self.xpath = self.driver.find_element_by_xpath
self.classname = self.driver.find_element_by_class_name
self.css = self.driver.find_element_by_css_selector
self.actions = ActionChains(self.driver)
#Open IE driver and new IE window
def launch(self):
self.driver = webdriver.Ie()
self.driver.get("https://www.mywebsite.com/")
logging.debug('Connected to SMS on '+str(date.today())+'')
def login(self):
self.username = self.classname("GJCH5BMD1C")
self.password = self.xpath("//*[#type='password']")
try:
self.username.send_keys("username")
self.password.send_keys("password")
self.log_in = self.xpath("//*[#class='GJCH5BMI-C']").click()
except:
os.system('python sms_generic_err.py')
logging.debug('FAILED LOGIN'+str(date.today())+'')
#Stock tab
def stock_tab(self):
#Only call when on stock tab
self.stock = self.xpath("//div[#class='GJCH5BMHEF' and text()=' Stock ']").click()
time.sleep(0.2)
def stock_tab_prd_select(self):
#opens prod chooser
self.stockselect = self.xpath("//span[#class='GJCH5BMKU' and text()='Select']").click()
def stock_searchbtn(self):
self.stocksearch = self.xpath("//*[#class='GJCH5BMJV']")
self.stocksearch.click()
def stock_tab_prd_clear(self):
#clears product
self.stockclear = self.xpath("//span[#class='GJCH5BMKU' and text()='Clear']").click()
def stock_resetbtn(self):
#stock reset button
self.stockreset = self.xpath("//span[#class='GJCH5BMKU' and text()='Reset']").click()
#Product Chooser
def prod_choose_searchbar(self):
#finds the searchbox and clicks
self.search = self.css(".GJCH5BMASD")
self.search.click()
print('paste value: '+str(self.variable))
#pastes in prod number from variable
self.clicksearch = self.actions.move_to_element(self.search).send_keys(calls_sms.stp(self)).perform()
print('paste value after: '+str(self.variable))
def prod_choose_clicksearch(self):
self.clicksearch = self.xpath("//*[#class='GJCH5BMPR']").click()
def prod_choose_clickadd(self):
self.clickadd = self.css(".GJCH5BMCHI").click()
def prod_choose_clickfinish(self):
self.clickfinish = self.xpath("//div[#class='GJCH5BMJYC GJCH5BMGYC' and text()='Finish']").click()
#these must be called manually in the script not through the class
def user_ask_invtab():
os.system('python sms_err_select_inv.py')
def user_ask_ciinsight():
os.system('python sms_err_select_ciinsight.py')
if __name__ == "__main__":
unittest.main()
#########################################################################
#########################################################################
#Check Territory
#NEEDS TO BE FIXED LATER!
#this will most likely be built in another module
class territory_check():
def check_exists_ci__by_xpath():
try:
webdriver.find_element_by_xpath("//*[#class='GJCH5BMOW']")
except NoSuchElementException:
return False
os.system("python sms_connected_ci.py")
return True
#########################################################################
#########################################################################
SMS = calls_sms()
#%#%#%#%#%#%#%#%#%#%#%#%
SMS.launch()
SMS.var()
SMS.login()
os.system('python sms_err_select_inv.py')
time.sleep(2)
SMS.stock_tab()
time.sleep(2)
SMS.beginprod()
SMS.stock_tab_prd_select()
time.sleep(1)
SMS.prod_choose_searchbar()
time.sleep(2)
SMS.prod_choose_clickfinish()
time.sleep(2)
SMS.stock_tab_prd_select()
time.sleep(1)
SMS.prod_choose_searchbar()
time.sleep(2)
SMS.prod_choose_clickfinish()
time.sleep(1)
SMS.stock_tab_prd_select()
time.sleep(1)
SMS.prod_choose_searchbar()
time.sleep(2)
SMS.prod_choose_clickfinish()
I want it to read the excel file, grab the value from the cell, paste it into send_keys. and then be able to call another function to move to the next cell below and loop only when called.
I figured it out finally. I have to update the actions variable or else the strings are stored in it each time. will post solution soon once its written