Шаблон объекта страницы - проблема с Webdriverwait - python - PullRequest
0 голосов
/ 15 января 2019

Я учу питона и селена. Я пытаюсь создать новый проект с шаблоном объекта Page, и у меня есть проблема с WebdriverWait, вы можете увидеть мой код, а затем я пишу, как получаю ошибку.

Метод на странице:

def testStart(self):
    WebDriverWait(self.driver, 15).until(
        expected_conditions.element_to_be_clickable((By.ID, 
        StartPage.username))
    )
    user = self.driver.find_element(*StartPage.username)
    user.click()

Мой тест - просто;)

startPage = StartPage(self.driver)
    startPage.testStart()

И локаторы:

username = (By.ID, 'username')

и ошибка:

selenium.common.exceptions.WebDriverException: Message:
invalid argument: 'value' must be a string

Когда я проверяю метод на странице:

def testStart(self):
    WebDriverWait(self.driver, 15).until(
        expected_conditions.element_to_be_clickable((By.ID, 
        *StartPage.username))
    )
    user = self.driver.find_element(*StartPage.username)
    user.click()

У меня было:

TypeError: find_element() takes from 1 to 3 positional arguments but 4 were given

Как я могу это изменить?

1 Ответ

0 голосов
/ 15 января 2019

Ошибка 1:

selenium.common.exceptions.WebDriverException: Сообщение: неверный аргумент: 'value' должно быть строкой

Ваш StartPage.username: username = (By.ID, 'username').

Теперь, когда вы ожидаете этот элемент с помощью:

WebDriverWait(self.driver, 15).until(
    expected_conditions.element_to_be_clickable((By.ID, 
    *StartPage.username))
)

Вы передаете ему By объект, а не ID ...

Это можно исправить с помощью:

WebDriverWait(self.driver, 15).until(
    expected_conditions.element_to_be_clickable(*StartPage.username)
)

Или измените StartPage.username на: username = 'username' и сохраните код в ожидании ...

Для получения дополнительной информации см. объекты страницы .

Надеюсь, это поможет вам!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...