Всем привет.
Есть такой кусок кода:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import ElementNotVisibleException
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import WebDriverException
import time
class Component:
def __init__(self, driver):
self.driver = driver
def TypeText(self, selector, value):
input_field = self.FindElement(selector)
try:
input_field.send_keys(value)
except ElementNotVisibleException:
# time.sleep(1)
input_field.send_keys(value)
def Click(self, selector):
element = self.FindElement(selector)
# try:
# element.click()
# except ElementNotVisibleException:
# # time.sleep(1)
# element.click()
# except WebDriverException:
# # time.sleep(1)
# element.click()
element.click()
def FindElement(self, selector):
# element = WebDriverWait(self.driver, 5).until(
# lambda driver: driver.find_element(By.CSS_SELECTOR, selector))
# # EC.presence_of_element_located((By.CSS_SELECTOR, selector)))
element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
)
print(element)
return element
Очень не хочется вставлять sleep'ы, потому что, на сколько мне известно, для этого существуют wait'ы в селениуме. Даже при
element = WebDriverWait(self.driver, 10).until(
EC.presence_of_element_located((By.CSS_SELECTOR, selector))
Traceback (most recent call last):
File "./main.py", line 40, in <module>
run()
File "./main.py", line 36, in run
p.setDateFilter(STARTDATE, ENDDATE)
File "/home/int/dev/python/den/lib/core/page.py", line 40, in setDateFilter
date.Click(self.locators['BankShifts.dateicon'])
File "/home/int/dev/python/den/lib/core/core.py", line 33, in Click
element.click()
File "/home/int/dev/python/den/lib/selenium/webdriver/remote/webelement.py", line 74, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/int/dev/python/den/lib/selenium/webdriver/remote/webelement.py", line 457, in _execute
return self._parent.execute(command, params)
File "/home/int/dev/python/den/lib/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/home/int/dev/python/den/lib/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///tmp/tmp5fwmfvli/extensions/fxdriver@googlecode.com/components/command-processor.js:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///tmp/tmp5fwmfvli/extensions/fxdriver@googlecode.com/components/command-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///tmp/tmp5fwmfvli/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///tmp/tmp5fwmfvli/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///tmp/tmp5fwmfvli/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)