EC 不使用来自另一个文件的定位器
EC don`t work with locators from another file
我正在尝试将我的定位器与页面对象 classes 分开。它与 driver.find_element 完美配合。但是,如果我尝试将它与 EC 一起使用,例如 self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
我收到这个错误
File "C:\FilePath\ClabtFirstForm.py", line 95, in wait_for_file_upload
wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
TypeError: __init__() takes 2 positional arguments but 3 were given
我的测试方法
def test_files_regular(self):
project_path = get_project_path()
file = project_path + "\Data\Media\doc_15mb.doc"
self.order.button_upload_files()
self.order.button_select_files(file)
self.order.wait_for_file_upload()
页面对象class
class CreateOrder(object):
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 25)
def button_upload_files(self):
self.driver.find_element(*OrderLocators.button_upload_files).click()
def button_select_files(self, file):
self.driver.find_element(*OrderLocators.button_select_files).send_keys(file)
def wait_for_file_upload(self):
self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[ng-show='item.isSuccess']")))
定位器
class OrderLocators(object):
button_upload_files = (By.CLASS_NAME, 'file-upload-label')
button_select_files = (By.CLASS_NAME, 'input-file')
file_upload_in_process = (By.CSS_SELECTOR, "[ng-show='item.isUploading']")
当您使用 *
将参数传递给 visibility_of_element_located()
时,您实际上传递的是扩展的可迭代对象 OrderLocators.file_upload_in_process
。也就是这个调用:
visibility_of_element_located(*OrderLocators.file_upload_in_process)
,等同于:
visibility_of_element_located(By.CLASS_NAME, 'input-file')
请注意第二行实际上是如何使用两个参数调用该方法的。
同时,这个条件的constructor expects only a single argument - 两个元素的tuple/list;因此例外。
修复 - 将它所期望的传递给它,元组本身,而不扩展它:
visibility_of_element_located(OrderLocators.file_upload_in_process)
我正在尝试将我的定位器与页面对象 classes 分开。它与 driver.find_element 完美配合。但是,如果我尝试将它与 EC 一起使用,例如 self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
我收到这个错误
File "C:\FilePath\ClabtFirstForm.py", line 95, in wait_for_file_upload
wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
TypeError: __init__() takes 2 positional arguments but 3 were given
我的测试方法
def test_files_regular(self):
project_path = get_project_path()
file = project_path + "\Data\Media\doc_15mb.doc"
self.order.button_upload_files()
self.order.button_select_files(file)
self.order.wait_for_file_upload()
页面对象class
class CreateOrder(object):
def __init__(self, driver):
self.driver = driver
self.wait = WebDriverWait(driver, 25)
def button_upload_files(self):
self.driver.find_element(*OrderLocators.button_upload_files).click()
def button_select_files(self, file):
self.driver.find_element(*OrderLocators.button_select_files).send_keys(file)
def wait_for_file_upload(self):
self.wait.until(EC.visibility_of_element_located(*OrderLocators.file_upload_in_process))
self.wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "[ng-show='item.isSuccess']")))
定位器
class OrderLocators(object):
button_upload_files = (By.CLASS_NAME, 'file-upload-label')
button_select_files = (By.CLASS_NAME, 'input-file')
file_upload_in_process = (By.CSS_SELECTOR, "[ng-show='item.isUploading']")
当您使用 *
将参数传递给 visibility_of_element_located()
时,您实际上传递的是扩展的可迭代对象 OrderLocators.file_upload_in_process
。也就是这个调用:
visibility_of_element_located(*OrderLocators.file_upload_in_process)
,等同于:
visibility_of_element_located(By.CLASS_NAME, 'input-file')
请注意第二行实际上是如何使用两个参数调用该方法的。
同时,这个条件的constructor expects only a single argument - 两个元素的tuple/list;因此例外。
修复 - 将它所期望的传递给它,元组本身,而不扩展它:
visibility_of_element_located(OrderLocators.file_upload_in_process)