如果滚动到下面的底部;我正在尝试使用process_records()
返回我的 last 函数末尾的第一个函数
。我的尝试返回Undefined variable 'process_records'pylint(undefined-variable)
def process_records(self, records, map_data, completed=None, errors=None):
"""Code to execute after webdriver initialization."""
series_not_null = False
try:
num_attempt = 0
for record in records.itertuples(): # not working
print(record)
series_not_null = True
self.navigate_to_search(num_attempt)
self.navigate_to_member(mrn)
self.navigate_to_assessment()
self.add_assessment(record, map_data)
self.driver.switch_to.parent_frame() # not working
sleep(.5)
except Exception as exc:
if series_not_null:
errors = self.process_series_error(exc)
return completed, errors
def navigate_to_search(self, num_attempt):
"""Uses webdriver to navigate to Search tab and select Member Status=All"""
if num_attempt == 0:
page_change_until(self.driver, By.XPATH, './/*[text()="Search"]')
wait_ready_state(self.driver)
else:
self.driver.switch_to.parent_frame()
elem = wait_until(self.driver, By.XPATH, './/*[text()="Search"]')
is_disp_n = 0
while True:
if elem.is_displayed():
break
else:
self.driver.switch_to.parent_frame()
is_disp_n += 1
sleep(1)
if is_disp_n == 20:
raise Exception('Could not find Search tab after 20 tries.')
num_attempt += 1
radio_locator = (By.XPATH, './/*[@type="RADIO"][@value="All"]')
while True:
break_while_timer = datetime.now()
if datetime.now() - break_while_timer > timedelta(seconds=20):
break_while = True
break
try:
if wait_until(self.driver, *radio_locator).is_selected():
pass
else:
wait_until(self.driver, *radio_locator).click()
break
except Exception:
sleep(1)
def navigate_to_member(self, mrn):
"""Finds member"""
wait_until(self.driver, By.XPATH, './/*[@name="MemberIdItem_1"]').clear()
wait_until(self.driver, By.XPATH, './/*[@name="MemberIdItem_1"]').send_keys(f'{mrn}'+Keys.ENTER)
page_change_until(self.driver, By.XPATH, f'.//*[text()="{mrn}"]')
wait_ready_state(self.driver)
def navigate_to_assessment(self):
"""Navigates to the appropriate contact log"""
self.driver.find_element_by_css_selector("div[eventproxy^='memberAssessment']").click() #clicks assessment icon
element = self.driver.find_element_by_xpath(f"//div[contains(text(), '{self.assessment_type}')]")
actions = ActionChains(self.driver)
actions.move_to_element(element).perform()
self.driver.find_element_by_xpath(f"//div[contains(text(), '{self.assessment_type}')]").click()
self.driver.find_element_by_css_selector("div[eventproxy^='createSelectedAssessmentsButton']").click()
def add_assessment(self, record, map_data):
"""Create contact log"""
qna_frame = self.driver.find_element_by_css_selector("iframe[id^='iccc']")
self.driver.switch_to.frame(qna_frame)
pages = self.driver.find_element_by_css_selector("ul[class='nav nav-pills nav-stacked qna-tabs']")
pages = pages.find_elements_by_css_selector("a")
for page in pages:
page.click()
# for record in records.itertuples(): #attempt
questions = self.driver.find_elements_by_css_selector("fieldset")
questions = [question for question in questions if question.text not in ("", " ", None)]
for question in questions[1:]:
q_text = question.find_element_by_css_selector("span[class='question-text ng-binding']").text
questionType = map_data.loc[map_data['question_text'] == q_text, 'question_type'].item()
answer = map_data.loc[map_data['question_text'] == q_text, 'map'].item()
answer = getattr(record, answer)
if answer not in ("", " ", "NaT", "NaN", None):
if questionType == 'checks':
self.choose_checks(question, answer)
else:
try:
if questionType == 'text':
self.driver.implicitly_wait(0)
(question.find_element_by_css_selector("textarea").send_keys(str(answer))
if
question.find_elements_by_css_selector("textarea")
else
question.find_element_by_css_selector("input").send_keys(answer))
self.driver.implicitly_wait(15)
elif questionType == 'date':
try:
answer = answer.strftime('%m/%d/%Y')
question.find_element_by_css_selector("input").send_keys(answer)
# page.click()
except Exception as e:
raise Errors.RequiredDataError('Issues with Assessment Date -- {}'.format(e))
elif questionType == 'radio':
question.find_element_by_css_selector("input[value='{}']".format(answer)).click()
except:
continue
else:
pass
self.driver.find_element_by_css_selector("#publishButton").click()
sleep(3)
WebDriverWait(self.driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".btn.btn-mini.btn-primary"))).click()
process_records()
我也尝试过:
self.process_records()
答案 0 :(得分:2)
整个代码块似乎在一个类中。因此,您应该使用self.process_records()
来调用该函数。
process_records
方法需要一些位置参数(除self外)-您可能也需要将这些参数传递给函数。