【问题标题】:InvalidArgumentException: Message: invalid argument: 'using' must be a stringInvalidArgumentException:消息:无效参数:“使用”必须是字符串
【发布时间】:2020-06-09 05:50:15
【问题描述】:

我对 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 文件的类,我有我所有的 xpaths

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"

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)))

缩进都可以

【问题讨论】:

  • 哪一行抛出错误信息?
  • 能否请您添加错误的完整堆栈跟踪?
  • @svetlannnka ..\pages\test_login.py:15: in login_user loginButton = self.driver.find_element((By.XPATH, Locators_test.loginlink_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_handler.check_response(response)
  • self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x0345FBF0> response = {'status': 400, 'value': '{"value":{"error":"invalid argument","message":"invalid argument: \'using\' must be a string...\n\\tRtlGetAppContainerNamedObjectPath [0x77AE662D+237]\\n\\tRtlGetAppContainerNamedObjectPath [0x77AE65FD+189]\\n"}}'}
  • @supputuri 错误出现在loginButton = self.driver.find_element((By.XPATH, Locators_test.loginlink_xpath)) Locators_test.loginlink_xpath = "//a[@id='login-link']" 上述cmets 中提到的错误消息

标签: python selenium testing automation automated-tests


【解决方案1】:

我自己通过从行中删除多余的括号来修复它

loginButton = self.driver.find_element((By.XPATH, Locators_test.loginlink_xpath))

正确的方法是

loginButton = self.driver.find_element(By.XPATH, Locators_test.loginlink_xpath)

ps:这适用于所有行。

【讨论】:

    【解决方案2】:

    这对我有用,

    locator = (By.XPATH, Locators_test.loginlink_xpath)
    self.driver.find_element(*locator).click()
    

    说明:*<arguments>中,除了第一个位置参数之外的所有位置参数都将打包在一个元组中,因为它们不会被更改,确切的属性将在第二步中反映出来.

    【讨论】:

      猜你喜欢
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-04-08
      • 2019-08-07
      • 2020-02-17
      • 1970-01-01
      相关资源
      最近更新 更多