Привет. Работаю над тестом, который проверяет работу некоторой формы. Трюк в том, что в зависимости от настроек количество заполняемых полей в форме может изменяться. Поэтому, чтобы не морочаться с локацией каждой отдельной строки, пытаюсь изобрести более ленивый метод. Для начала, например, проверяем валидацию. Дл этого хочу стереть данные из всех текстовых полей.
def clear_all_fields(driver):
text_fields = driver.find_elements_by_xpath("//form[@id='create_order_form']/div/div/div[@class='form-line']/div[@class='form-inputs']/input[@type='text']")
for field in text_fields:
field.clear()
Так как в коде страницы есть поля, скрытые настройками, то добавляем множество форм, которое трогать не нужно.
def clear_all_fields(driver):
text_fields = driver.find_elements_by_xpath("//form[@id='create_order_form']/div/div/div[@class='form-line']/div[@class='form-inputs']/input[@type='text']")
not_displayed_text_fields = driver.find_elements_by_xpath("//form[@id='create_order_form']/div/div/div[@style='display: none;']")
for field in text_fields:
if field not in not_displayed_text_fields:
field.clear()
И тут собственно начинаются грабли. При прогоне говорит, что
Traceback (most recent call last):
File "test_order.py", line 81, in test_order
clear_all_fields(self.driver)
File "test_order.py", line 68, in clear_all_fields
field.clear()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 53, in clear
self._execute(Command.CLEAR_ELEMENT)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/remote/webelement.py", line 194, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/remote/webdriver.py", line 153, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium-2.15.0-py2.7.egg/selenium/webdriver/remote/errorhandler.py", line 147, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: u'Element is not currently interactable and may not be manipulated'
Очевидно, селениум всё равно обращается к скрытым полям и пытается их очистить. Помогите разобраться, где я туплю