I am using explicit wait like below to check if element is clickable.
WebDriverWait(driver, 30).until(
expected_conditions.element_to_be_clickable((By.CSS_SELECTOR, "#search")))
But I get error
<class 'selenium.common.exceptions.WebDriverException'>
Message: The command 'GET /session/.../displayed' was not found.
If I use time.sleep()
it works fine instead of explicir wait it works fine. I have initialized safari driver as
from selenium.webdriver import Safari
driver = Safari()
Here is stacktrace
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/wait.py", line 71, in until
value = method(self._driver)
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 283, in __call__
element = visibility_of_element_located(self.locator)(driver)
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 127, in __call__
return _element_if_visible(_find_element(driver, self.locator))
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/support/expected_conditions.py", line 147, in _element_if_visible
return element if element.is_displayed() == visibility else False
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webelement.py", line 490, in is_displayed
return self._execute(Command.IS_ELEMENT_DISPLAYED)['value']
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "/Users/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: The command 'GET /session/7.../displayed' was not found.
This error message...
...implies that the GET request to
/session/{session id}/element/{element id}/displayed
failed.element displayed
As per the WebDriver W3C Editor's Draft the element displayed algorithm is a boolean state where
true
signifies that the element is displayed andfalse
signifies that the element is not displayed. To compute the state on element, invoke theCall(bot.dom.isShown, null, element)
. If doing so does not produce an error, return the return value from this function call. Otherwise return an error with error code unknown error.This function is typically exposed to GET requests with a URI Template of
Analysis
You have invoked:
element_to_be_clickable()
class internally invokesvisibility_of_element_located()
and is defined as:Now,
visibility_of_element_located()
class returns_element_if_visible(_find_element(driver, self.locator))
which is defined as:Again,
_element_if_visible()
returnselement if element.is_displayed() == visibility else False
which is defined as:So, as the
if()
condition ofelement.is_displayed() == visibility
failed hence you see the error asGET
request to the/session/{session id}/element/{element id}/displayed
endpoint failed.Without the relevant HTML and previous steps it is tough to guess the exact reason but possibly can be either of the following:
Reason
The reason for NoSuchElementException can be either of the following :
<iframe>
tag.Solution
The solution to address NoSuchElementException can be either of the following :
Adopt a Locator Strategy which uniquely identifies the desired WebElement. You can take help of the Developer Tools (Ctrl+Shift+I or F12) and use Element Inspector.
Here you will find a detailed discussion on how to inspect element in selenium3.6 as firebug is not an option any more for FF 56?
Use
execute_script()
method to scroll the element in to view as follows :Here you will find a detailed discussion on Scrolling to top of the page in Python using Selenium
Incase element is having the attribute style="display: none;", remove the attribute through
executeScript()
method as follows :To check if the element is within an
<iframe>
traverse up the HTML to locate the respective<iframe>
tag andswitchTo()
the desired iframe through either of the following methods :Here you can find a detailed discussion on How can I select a html element no matter what frame it is in in selenium?.