Python InvalidArgumentException:消息:无效参数:';使用';一定是字符串
我是python新手,尝试创建可重用代码。当我试图通过传递Login类下使用的所有参数来调用test_main.py中的类Login和函数Login_user时,我得到一个错误,即InvalidArgumentException:Message:invalid参数:“using”必须是字符串 在pytest上运行的test_main.py文件 Locators\u test是test\u Locators.py文件的一类,我在其中拥有所有XPath 测试定位器.pyPython InvalidArgumentException:消息:无效参数:';使用';一定是字符串,python,selenium,testing,automation,automated-tests,Python,Selenium,Testing,Automation,Automated Tests,我是python新手,尝试创建可重用代码。当我试图通过传递Login类下使用的所有参数来调用test_main.py中的类Login和函数Login_user时,我得到一个错误,即InvalidArgumentException:Message:invalid参数:“using”必须是字符串 在pytest上运行的test_main.py文件 Locators\u test是test\u Locators.py文件的一类,我在其中拥有所有XPath 测试定位器.py class Locators
class Locators_test():
loginlink_xpath = "//a[@id='login-link']"
login_email = "xxxxx"
login_password = "xxxxx"
loginemail_id = "dnn_ctr1179_Login_txtEmail"
loginpassword_id = "dnn_ctr1179_Login_txtPassword"
clicklogin_id = "dnn_ctr1179_Login_btnLogin"
test_login.py
from Smoketest.locatorfile.test_Locators import Locators_test
class Login():
def __init__(self,driver):
self.driver = driver
def login_user(self,driver):
try:
loginButton = self.driver.find_element((By.XPATH, Locators_test.loginlink_xpath))
while loginButton.click() is True:
break
time.sleep(3)
self.driver.execute_script("window.scrollBy(0,300);")
EmailField = self.driver.find_element((By.ID, Locators_test.loginemail_id))
EmailField.send_keys(Locators_test.login_email)
PasswordField = self.driver.find_element((By.ID, Locators_test.loginpassword_id))
PasswordField.send_keys(Locators_test.login_password)
ClickLogin = self.driver.find_element((By.ID, Locators_test.clicklogin_id))
while ClickLogin.click() is True:
break
time.sleep(5)
userName = self.driver.find_element((By.XPATH, Locators_test.username_xpath))
print("Logged in as", userName.text)
except StaleElementReferenceException or ElementClickInterceptedException or TimeoutException as ex:
print(ex.message)
test_main.py
def test_setup():
driver = webdriver.Chrome(executable_path= Locators_test.browser_path)
driver.maximize_window()
driver.delete_all_cookies()
driver.get(homePage)
driver.implicitly_wait(5)
yield
print("test complete")
def test_login(test_setup):
from Smoketest.pages.test_login import Login
lo = Login(driver)
lo.login_user(((Locators_test.loginlink_xpath,Locators_test.loginemail_id,Locators_test.login_email,Locators_test.loginpassword_id,Locators_test.login_password,Locators_test.clicklogin_id,Locators_test.username_xpath)))
缩进都很好我通过从行中删除额外的一对括号来修复它
loginButton=self.driver.find_元素((By.XPATH,Locators_test.loginlink_XPATH))
正确的方法是
loginButton=self.driver.find_元素(By.XPATH,Locators\u test.loginlink\u XPATH)
ps:这适用于所有线路。这对我来说很有效
locator = (By.XPATH, Locators_test.loginlink_xpath)
self.driver.find_element(*locator).click()
说明:在
*
中,除第一个位置参数外的所有位置参数都将打包在一个元组中,因为它们不会被更改,确切的属性将反映在第二步中。哪一行抛出错误消息?请添加错误的完整堆栈跟踪?@svetlannka。\pages\test\u login.py:15:in login\u user login button=self.driver.find\u元素((By.XPATH,Locators\u test.loginlink\u XPATH))..\..\venv\lib\site packages\selenium\webdriver\remote\webdriver.py:978:in find_element'value':value})['value']\..\venv\lib\site packages\selenium\webdriver\remote\webdriver.py:321:in execute self.error\u handler.check\u响应(response)
self=response={'status':400,'value':{“value”:{“error”:“无效参数”,“消息”:“无效参数:\'using\'必须是字符串…\n\\TrtGetAppContainerNamedObjectPath[0x77AE662D+237]\\n\\TrtGetAppContainerNamedObjectPath[0x77AE65FD+189]\\n”}}
@SupportUri错误发生在loginButton=self.driver.find\u元素((By.XPATH,Locators\u test.loginlink\u XPATH))
定位器\u test.logiink\u XPATH=“/a[@id='login-link']”
在上述评论中提到了错误消息