gpt4 book ai didi

python - 无效参数异常 : Message: invalid argument: 'using' must be a string

转载 作者:行者123 更新时间:2023-12-04 16:41:15 28 4
gpt4 key购买 nike

我对 python 很陌生,试图创建可重用的代码。当我尝试通过传递在 Login 类下使用的所有参数来调用 test_main.py 中的类 Login 和函数 login_user 时,我收到一个错误,如 InvalidArgumentException: Message: invalid argument: 'using' must be a string。

在 pytest 上运行的 test_main.py 文件。

Locators_test 是 test_Locators.py 文件的类,我有我所有的 xpath

test_Locators.py

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"

测试登录.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_element((By.XPATH, Locators_test.loginlink_xpath))
正确的方法是
loginButton = self.driver.find_element(By.XPATH, Locators_test.loginlink_xpath)
ps:这适用于所有行。

关于python - 无效参数异常 : Message: invalid argument: 'using' must be a string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60395570/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com