Hi I have just learnt about Object Orientated Programming. However, recently I came across an issue...
I would like to ask if there is a way to import a variable from one file to the next, or possible any other way I can go about finding an element in file2 using a value obtained from a method in file1. I thought about importing the value saved within the max_sim variable found through my method in file1 and use it within another locator in file2. However, I run into an error as max_sim is not recognized in my locators file (file2)
This file1 contains all my locators for my bot program:
@property
def simulator_mod(self):
locator = (By.XPATH, '//input[@value="' str(max_sim) '"]')
return BaseElement(driver=self.driver, by=locator[0], value=locator[1])
This other file2 contains all my methods that help me run my program:
class BaseElement(object):
def __init__(self, driver, by, value):
self.driver = driver
self.value = value
self.by = by
self.locator = (self.by, self.value)
self.web_element = None
def find_elements(self):
elements = WebDriverWait(self.driver, 10).until(EC.visibility_of_all_elements_located(locator=self.locator))
self.web_element = elements
return None
def select_sim_element(self):
self.find_elements()
simulator_list = []
simulator_elements = self.web_element
breakpoint()
for sim in simulator_elements:
sim_list_val = sim.get_attribute("value")
simulator_list.append(int(sim_list_val))
max_sim = max(simulator_list)
return max_sim
CodePudding user response:
It won't let me put it in a comment so here is how it would look:
#File 1:
x=0
while x==0:
variable_file = open("VariableFile.txt", "r ")
variable_file.truncate() #This clears the file
variable file = #Input the variable contents or variable here
#File 2:
x=0
while x==0:
variable_file = open("VariableFile.txt", "r")\
variable_in_file_2 = variable_file
variable_file.close ()
CodePudding user response:
You could write it to a text file in file 1 and then read that file in file 2