I want to use WebdriverWait for when clicking elements in Python Webdriver.
I get the following TimeoutException error when using WebdriverWait:
Traceback (most recent call last):
File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore\TestCases\AdministrationPage_TestCase.py", line 30, in test_add_Project
administration_page = login_page.clickAdministration()
File "C:\Users\riaz.ladhani\PycharmProjects\Selenium Webdriver\ClearCore\Pages\login.py", line 46, in clickAdministration
WebDriverWait (self.driver, 10).until(lambda d: self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click())
File "C:\Python27\lib\site-packages\selenium\webdriver\support\wait.py", line 75, in until
raise TimeoutException(message, screen, stacktrace)
TimeoutException: Message:
If I use time.sleep(10)
it works ok and clicks the elements. I have reverted all my links to time.sleep for now until I can get WebdriverWait
to work properly.
My code snippet for WebdriverWait is:
class LoginPage(BasePage):
#Click Administration from top menu
def clickAdministration(self):
WebDriverWait (self.driver, 10).until(lambda d: self.driver.find_element(*MainPageLocators.AdministrationButton_xpath).click())
#time.sleep(10)
return AdministrationPage(self.driver)
The imports are:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
class LoginPage_TestCase(unittest.TestCase):
def test_add_Project(self):
login_page = login.LoginPage(self.driver)
login_page.userLogin_valid()
administration_page = login_page.clickAdministration()
Is my WebdriverWait
syntax correct? Why the TimeoutException?
If I use time.sleep(secs)
, it works fine but not the best efficient way to do it.